我想檢查用戶名是否已存在於數據庫中。使用參數化查詢檢查重複的用戶名
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