Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...