Cannot implicitly convert type 'decimal' to 'int'. An explicit conversion exists (are you missing a cast?)
I am calling a GetSerialNo function but it showing some error like:
Cannot implicitly convert type 'decimal' to 'int'. An explicit conversion exists (are you missing a cast?).
Can anyone help me to solve this issue?
Here is the code:
int slNo= GetSerailNo(keydata);
private int GetSerailNo(Stri开发者_JAVA技巧ng keydata)
{
SqlConnection con = new SqlConnection(@"server=Servername;database=DBNAME;uid=Username;pwd=Pwd;max pool size=250;Connect Timeout=0");
con.Open();
cmd = new SqlCommand("select isnull(max(slno)+1,1) from d001docs where source_keydata='" + keydata + "'", con);
dynamic no = cmd.ExecuteScalar();
cmd.Dispose();
con.Close();
return no;
}
Thanks in advance
cmd.ExecuteScalar()
returns a decimal, which you need to convert to int before you return it, for example:
return Convert.ToInt32(no);
use:
int no = (int)cmd.ExecuteScalar();
精彩评论