开发者

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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜