登录判断用户名和密码是否正确的代码(链接和读取数据库)

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>");
        }
posted @ 2007-07-26 20:44  星空竹月  阅读(4407)  评论(1编辑  收藏  举报