Forum Moderators: open

Message Too Old, No Replies

Trouble understanding session variables

         

JohnWise

4:02 pm on Mar 24, 2003 (gmt 0)

10+ Year Member



I have a login page that I am trying to do this with. Upon validation, I send the user to a page that is displayed using a datagrid. I would like to add the user's expiration date under the data on this page. I want to do this with a session variable, at this point to just get a handle on how to work with them.
I am not exactly how to declare the session variable. I am using VB.net. I simply want to grab that field, which is a datetime, in my table.
The following is my code that works fine for logging in to access the page with the data.

<code>Sub Login_Click(Sender As Object, E As EventArgs)
If Page.IsValid Then
Dim userDS As New DataSet
userDS = QueryMethod(UserName.Text, UserPass.Text)
If userDS.Tables(0).Rows.Count = 1 Then
FormsAuthentication.RedirectFromLoginPage(UserName.Text, True)
Else
Msg.Text = "Invalid Credentials : Please try again"
End If
En If
End Sub
Function QueryMethod(ByVal username As String, ByVal password As String) As DataSet
Dim connectionString As String = "server........"
Dim sqlConnection As sqlConnection = New sqlConnection(connectionString)
Dim queryString As String = "SELECT [tusers].* FROM [tusers] WHERE (([tusers].[username] = @username) AND ([tusers].[userpassword] = @userpassword))"

sqlCommand.Parameters.Add("@username", sqldbType.VarChar).value= username
sqlCommand.Parameters.Add("@userpassword", sqldbType.VarChar).value = password
Dim dataAdapter As sqlDataAdapter = New sqlDataAdapter(sqlCommand)
Dim dataSet As DataSet = New DataSet
dataAdapter.Fill(dataSet)
Return dataSet
End Function
</code>
Like I said, my main problem seems to be understanding the transfer of the data from the database to the program. Thanks for any help.
John

chris_f

3:04 pm on Mar 25, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't quite understand your problem, however, I'm hoping the following will help.

In your global.asa create a OnSession_Start Function. In there you can set a variable called WIDGET as empty by doing the following:

Widget = ""

To fill this in your code you will just use the following:

Session("Widget") = "25-Jan-03"

And you can access it with

<%= Session("Widget") %>

Hope this helps in some way.
Chris