我想检查数据库中是否已经存在用户名。
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();
}
但在这里,i
总是给予-1
问题是什么。?