我想检查用户名是否已存在于数据库中。使用参数化查询检查重复的用户名
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["DBCOnn"].ToString());
try
{
con.Open();
SqlCommand cmd = new SqlCommand("select client_id from tbl_client where [email protected]", 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
这是什么问题?
哎呀,获取计数,它为什么没有来我mind..Thanks..It现在的作品。 – 2013-03-11 10:19:41