【发布时间】:2015-11-13 02:36:00
【问题描述】:
我想进行会话,但我不知道从哪里开始。我自己登录,但没有使用会话,我必须进行会话。以下是我到目前为止所做的代码。
Protected Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogin.Click
If txt_username.Text = "" Or txt_password.Text = "" Then
error_usr_invalid.Visible = False
If txt_username.Text = "" Then
error_usr_blank.Visible = True
ElseIf txt_username.Text <> "" Then
error_usr_blank.Visible = False
End If
If txt_password.Text = "" Then
error_pwd_blank.Visible = True
ElseIf txt_username.Text <> "" Then
error_pwd_blank.Visible = False
End If
ElseIf txt_username.Text <> "" And txt_password.Text <> "" Then
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)
con.Open()
Dim cmd As New SqlCommand("select * from users where username = '" + txt_username.Text + "' and Password = '" + txt_password.Text + "'", con)
cmd.Parameters.AddWithValue("@username", txt_username.Text)
cmd.Parameters.AddWithValue("@password", txt_password.Text)
Dim da As New SqlDataAdapter(cmd)
Dim dt As New DataTable()
da.Fill(dt)
If dt.Rows.Count > 0 Then
error_usr_invalid.Visible = False
error_usr_blank.Visible = False
error_pwd_blank.Visible = False
Response.Redirect("main.aspx")
Else
error_usr_invalid.Visible = True
error_usr_blank.Visible = False
error_pwd_blank.Visible = False
End If
End If
请通过在此代码中提出您的想法来帮助我。
【问题讨论】: