We help IT Professionals succeed at work.
Get Started

how to store the result of a query in a session variable

zebrain777
zebrain777 asked
on
338 Views
Last Modified: 2012-05-11
Hi experts,

I've a problem to get an result in a session variable.
The customer must login and if correct than I want to search how many records for that customer are in the database and want to store it in a session variable so I can use it on different pages.

Anybody has the solution ? I think I make a mistake with the objdatareader.item or the sql query but I've searched on the web and the experts-exchange but can't find the solution.

Regards,
Rob
Here is the part of my code.
objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_Data\inetds.mdb"))

strSQLQuery = "Select * from inetmem WHERE Loginnaam = '" & TbUsernaam.Text & "' And pw = '" & TbWachtwoord.Text & "'"

objConnection.Open()
objCommand = New OleDbCommand(strSQLQuery, objConnection)
objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)

If objDataReader.Read() Then
   test1 = objDataReader.GetName(1)
   test2 = objDataReader.GetValue(2)
   objConnection.Close()
----> Until here it works fine.
'--- now I want a select count 
   objConnection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("App_Data\inetds.mdb"))

   strSQLQuery = "Select count(*) as dscounter from inetds WHERE database = 'XXX' And corrnr = 1 "

   objConnection.Open()
   objCommand = New OleDbCommand(strSQLQuery, objConnection)
   objDataReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection)
   Session(DSaantal) = objDataReader.Item("DScounter")
   Response.Redirect("main.aspx")
Else
   objConnection.Close()
   Return
End If

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 2 Answers and 14 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE