登录判断用户名和密码是否正确的代码(链接和读取数据库)
SqlConnection sqlcon;
string strCon = "Data Source=(local);Database=db_11;Uid=sa;Pwd=";
string sqlstr = "select id,mima from tb_Member111 where id='" + this.TextBox2.Text.Trim() + "' and mima='" + this.TextBox3.Text.Trim() + "'";
sqlcon = new SqlConnection(strCon);
SqlCommand com = new SqlCommand(sqlstr, sqlcon);
sqlcon.Open();
SqlDataReader read = com.ExecuteReader();
if (read.Read())
{
//向目标页面传递数据
string sUrl = "BrowserGoods.aspx?id=" + TextBox2.Text;
Response.Redirect(sUrl);
}
else
{
Response.Write("<script>alert('用户名或密码错误')</script>");
}
string strCon = "Data Source=(local);Database=db_11;Uid=sa;Pwd=";
string sqlstr = "select id,mima from tb_Member111 where id='" + this.TextBox2.Text.Trim() + "' and mima='" + this.TextBox3.Text.Trim() + "'";
sqlcon = new SqlConnection(strCon);
SqlCommand com = new SqlCommand(sqlstr, sqlcon);
sqlcon.Open();
SqlDataReader read = com.ExecuteReader();
if (read.Read())
{
//向目标页面传递数据
string sUrl = "BrowserGoods.aspx?id=" + TextBox2.Text;
Response.Redirect(sUrl);
}
else
{
Response.Write("<script>alert('用户名或密码错误')</script>");
}