我正在尝试制作一个登录页面。
我有一个包含四列的用户表。
id 用户名 密码 admin
我有一个帖子,但我无法登录。这是我的代码:
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;
}