9.3.1.txt

来自「protected void Button1_Click」· 文本 代码 · 共 34 行

TXT
34
字号
 protected void Button1_Click(object sender, EventArgs e)
    {
        //连接数据库
	string strConn="server=Localhost;uid=sa;pwd=;database=Aspnet";
	string strCmd="select count(*) from Ex09_User where(UserName like'"+TextBox1.Text+"'and Pwd like'"+TextBox2.Text+"')";
	SqlConnection myConnection=new SqlConnection();
    myConnection.ConnectionString=strConn;
	SqlCommand myCommand=new SqlCommand(strCmd,myConnection);
	myCommand.Connection.Open();
	//检索出的用户数
	int flag=(int)myCommand.ExecuteScalar();
    myCommand.Connection.Close();
	myConnection.Close();
	if(flag>0)//用户存在
	{
		Session["username"]=TextBox1.Text;
		Response.Redirect("Ex09_03.aspx");
	}
	else//用户不存在
	{
		Label1.Text="对不起!用户名和密码不符,请重新输入.";
		TextBox1.Text="";
        TextBox2.Text="";
	}
    }


    protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Redirect("Ex09_02.aspx");
    }


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?