ユーザーが存在するかどうかを確認しようとします。
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");
私のテーブル構造は
間違いが見つかりません。ありがとうございます。