我嘗試檢查用戶存在或not.I嘗試:
的SQLException是由用戶代碼未處理的在C#
public static bool GetUser(string tblName, string UserName,string Password,string Usertype)
{
try
{
using (SqlConnection con = Connection.GetConnection())
{
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "select count(UserName) from " + tblName + " where Password=" + Password + " and usertype=" + Usertype + " and username="+ UserName + "";
object obj = cmd.ExecuteScalar();
if (obj != null)
return true;
return false;
}
}
}
catch (Exception ex)
{
throw ex;
}
}
當我把這個方法我得到了下面的錯誤。
連接成功建立,我稱這種方法是這樣的。
bool Check = UserLogin.GetUser("OnlineCertificationLogin", "admin", "admin", "Admin");
我的表結構
無法找到我的mistake.Thanks。