I want to check if username already exist in the database.
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["DBCOnn"].ToString());
try
{
con.Open();
SqlCommand cmd = new SqlCommand("select client_id from tbl_client where client_name=@cname", con);
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("@cname", DbType.String).Value = usernm;
int i = cmd.ExecuteNonQuery();
if (i > 0)
return true;
else
return false;
}
catch (Exception ex)
{
throw new Exception("CheckExistingClient:" + ex.Message, ex.InnerException);
}
finally
{
con.Close();
}
But here, i
always giving as -1
What is the problem.?