Cannot implicitly convert type 'decimal' to 'int'. An explicit conversion exists (are you missing a cast?)
<p>I am calling a GetSerialNo function but it showing some error like:</p>

<p><code>Cannot implicitly convert type 'decimal' to 'int'. An explicit conversion exists (are you missing a cast?).</code></p>

<p>Can anyone help me to solve this issue?</p>

<p>Here is the code:</p>

<pre><code>int slNo= GetSerailNo(keydata);

private int GetSerailNo(String 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;
}
</code></pre>

<p>Thanks in advance</p>
