我的default.aspx上有以下代码
Label1.Text = Session("valueName").ToString()
我的login.aspx上的以下代码
Dim strCon As String = ConfigurationManager.ConnectionStrings(“Goed”)。ConnectionString
'Create Connection String And SQL Statement
Dim strSelect As String = "SELECT COUNT(*) FROM tbl_LogIn WHERE Gebruiker = @Gebruiker AND Wachtwoord = @Wachtwoord"
Dim con As New SqlConnection(strCon)
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = strSelect
Dim Gebruiker As New SqlParameter("@Gebruiker", _
SqlDbType.VarChar)
Gebruiker.Value = TxtUs.Text.Trim().ToString()
cmd.Parameters.Add(Gebruiker)
Dim Wachtwoord As New SqlParameter("@Wachtwoord", _
SqlDbType.VarChar)
Wachtwoord.Value = TxtPw.Text.Trim().ToString()
cmd.Parameters.Add(Wachtwoord)
con.Open()
Dim result As Integer = DirectCast(cmd.ExecuteScalar(), Int32)
con.Close()
If result >= 1 Then
Response.Redirect("default.aspx")
Session("valueName") = TxtUs.Text.ToString()
Else
lblMsg.Text = "Gebruikers naam en of wachtwoord kloppen niet"
End If
End Sub
但它似乎没有帮助。我没有得到任何错误或任何想法,任何想法?
答案 0 :(得分:2)
Redirect
方法结束执行,因此您必须在重定向之前设置会话变量:
Session("valueName") = TxtUs.Text.ToString()
Response.Redirect("default.aspx")
答案 1 :(得分:0)
您在设置会话之前重定向。您应首先设置会话,然后重定向页面。
或者
您的结果变量不是1或大于1.您应该检查