Hi,
You can try this
select sum(isnull(amountpaid,0)) as [sum] from tbl_payments where uid=29
and in aspx.cs file write following code
----------------------First Solution-----------------------------
if (Cmd.ExecuteScalar().GetType().ToString() != "System.DBNull")
{
}
----------------------Second Solution----------------------------
DataTable dt=new DataTable();
SqlDataAdapter da=new SqlDataAdapter(cmd);
da.Fill(dt);
if(dt.Rows.Count > 0)
{
int sum=Convert.TOInt64(dt.Rows[0][0].ToString());
}
Check It Out
Best Luck
Happy Coding :)