注册 登录
编程论坛 ASP.NET技术论坛

文本与数据库内容比较

yxhrgyj 发布于 2012-03-23 11:59, 451 次点击
string username = TxtName.Text.Trim();
        string userpwd = TxtPsw.Text.Trim();
        SqlConnection conn=new SqlConnection();
        conn.ConnectionString=(@"Data Source=RGYJ-AVTYN682XD;Initial Catalog=库;User ID=sa;Password=sa123456789");
        conn.Open();
        string cmdStr = "select * from 用户信息 where 用户名='" + username + "' and 密码='" + userpwd + "'";
        SqlCommand cmd = new SqlCommand(cmdStr,conn);
        SqlDataReader myReader = cmd.ExecuteReader();
        if (myReader.Read())
        {
            BtnSure.PostBackUrl = "~/Welcome.aspx";
        }
        else
            Response.Redirect("Error.aspx");
        conn.Close();
        conn.Dispose();


这是核心代码,可是我要点击2次按钮才跳转  怎么实现一次点击就实现比较和跳转
2 回复
#2
guming2012-03-23 16:31
那你就不要在按钮里边设置跳转,而是直接使用Response.Redirect("~/Welcome.aspx");就可以了...
#3
shangsharon2012-03-25 03:32
同意楼上的!
1