请写出button的单击事件
发布网友
发布时间:2022-04-26 09:56
我来回答
共4个回答
热心网友
时间:2022-04-19 06:49
protect void button1_Click(Object sender,EventArgs)
{
string userName=textBox1.Text.Trim();
string userPwd=textBox2.Text.Trim();
SqlConnection con=new SqlConnection("Server=.;database=Test;uid=sa;pwd=sa");
Sqlcommand cmd=new Sqlcommand("Select count(*) from where username='"+userName+"' and userpwd='"+userPwd+"' ",con);
try{
con.Open();
if(int count=Convert.toInt32(cmd.ExecuteScalar()>0)
{
Response.Rediret("manager.aspx");
}
else
{
Response.Write("<script>alert('用户名活密码错误')</script>");
}
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
Finaly
{
con.Close();
con.Dipose();
cmd.Dipose();
}
点击就写这个 能运行!
热心网友
时间:2022-04-19 08:07
首先在这个aspx页面上给button加上事件
大概就是
<asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" />
然后你在aspx.cs文件里写这样的东西
protected void Button2_Click(object sender, EventArgs e)
{
}
括号里写你的逻辑
热心网友
时间:2022-04-19 09:41
Dim m_Conn As ADODB.Connection
Private Sub cmdOK_Click()
Static nErr As Integer
Dim bErr As Boolean
Dim rs As ADODB.Recordset
Dim strSql As String
If txtUser.Text = "" Or txtPwd.Text = "" Then
MsgBox "用户或密码不能为空!", vbCritical, "错误"
bErr = True
Else
Set m_Conn = OpenConnForSqlServer("XSFHLZH\SQLEXPRESS", "xsfh", "")
strSql = "select * from users where name = '" & txtUser.Text & "' and password='" & txtPwd.Text & "'"
Set rs = OpenRecordset(strSql, m_Conn)
If rs.EOF Then
MsgBox "错误的用户名或密码!", vbCritical, "错误"
bErr = True
Else
Unload Me
frmMDI.Show
End If
m_Conn.Close
End If
If bErr Then
nErr = nErr + 1
If nErr = 3 Then
Unload Me
Else
txtUser.Text = ""
txtPwd.Text = ""
txtUser.SetFocus
End If
End If
End Sub
Private Sub cmdCancle_Click()
Unload Me
End Sub
改改控件OK
热心网友
时间:2022-04-19 11:33
string strConn = @"Data Source=127.0.0.1;Initial Catalog=user;User ID=sa;Password=sa";
string strUserName = textBox1.Text.Trim();
string strUserPwd = textBox2.Text.Trim();
if (!string.IsNullOrEmpty(strUserName) && !string.IsNullOrEmpty(strUserPwd))
{
bool flag = false;
try
{
SqlConnection conn = new SqlConnection(strConn);
conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.CommandText = @"select userid,username,userpwd from userinfo where username='" + strUserName + "' and userpwd='" + strUserPwd + "'";
cmd.Connection = conn;
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
//合法用户
dr.Read();
Session["userid"] = dr["userid"].ToString();
Session["username"] = dr["username"].ToString();
flag = true;
}
else
{
//不合法用户
flag = false;
}
dr.Close();
cmd.Dispose();
conn.Close();
}
catch (Exception ex)
{
label1.Text = ex.Message;
}
if (false == true)
{
Response.Redirect("manager.aspx");
}
else
{
label1.Text = "用户名或密码错误!";
}
}
else
{
label1.Text="用户名和密码不能为空!";
}