ログインページを作成しようとしています。
4つの列を持つユーザー用のテーブルがあります。
idユーザー名パスワード管理者
投稿が1つありますが、ログインできません。コードは次のとおりです。
try
{
string strcon = System.Configuration.ConfigurationManager.ConnectionStrings["blogCS"].ToString();
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = strcon;
myConnection.Open();
string strSql = "SELECT COUNT(*) FROM users WHERE username=' " + txtUsername + "' AND password='";
SqlCommand command = new SqlCommand(strSql, myConnection);
int count = Convert.ToInt32(command.ExecuteScalar());
myConnection.Close();
if (count == 1)
Response.Redirect("index.aspx");
else
lblStatus.Text = Convert.ToString(count);
}
catch (Exception k)
{
lblStatus.Text = k.Message;
}