timothy2l Posted September 17, 2003 Posted September 17, 2003 What is the syntax to save a value from a database field as a session variable? I have the connection and sql statement to select the field, but I dont know how to set it as a session variable. What do i do after the sql statement? Thanks Quote
Moderators Robby Posted September 17, 2003 Moderators Posted September 17, 2003 Session("SomeVar") = strSomeVar Quote Visit...Bassic Software
timothy2l Posted September 17, 2003 Author Posted September 17, 2003 How do i set the DB value as strSomeVar? Here is what I have: sql = "SELECT Username FROM Users WHERE Username = '" + txtUsername.text + "'" From here I get confused because I dont know how to store the selected value in order to set it to a variable. Also, how do I go about coding the possibility that there is no value in the DB field that matches the Username. Thanks Quote
Moderators Robby Posted September 17, 2003 Moderators Posted September 17, 2003 what object are you using to get the values from the database? (datareader, dataAdapter...) Quote Visit...Bassic Software
timothy2l Posted September 18, 2003 Author Posted September 18, 2003 Here is what I have: ------------------------------------------------------------------------------------ Dim myConnection As OleDbConnection Dim cmd As OleDbCommand Dim myCommand As OleDbDataAdapter Dim connStr As String Dim sql As String connStr = "Provider=Microsoft.Jet.OLEDB.4.0; Password='';User ID=Admin; Data Source=C:\Inetpub\wwwroot\AlumniProject\Databases\alumniDatabase.mdb;Mode=Share Deny None;" myConnection = New OleDbConnection(connStr) myConnection.Open() cmd = New OleDbCommand("SELECT UserName FROM Graduates WHERE UserName = '" + txtUsername.Text + "' and Password='" + txtUsername.Text + "'", myConnection) txtUsername2.Text = cmd.ExecuteReader() txtPassword2.DataSource= cmd.ExecuteReader() If txtUsername2.Text = "" Then Response.Redirect("index.aspx") Else Session("username") = txtUsername2.Text Session("password") = txtPassword2.Text lblTest.Text = Session("username") End If ------------------------------------------------------------------------------------ txtUsername2 and txtPassword2 are hidden fields I am trying to use to store the corresponding DB values. I am getting an error in the highlighted lines. I tried ".text" and "DataSource" but neither work and DataSource is not a valid property of a txtBox. I just put them there to show that I have already tried them. Quote
timothy2l Posted September 19, 2003 Author Posted September 19, 2003 Nevermind, I solved the problem. Thanks Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.