Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Select statement for more than one field 1

Status
Not open for further replies.

boatdrinks

IS-IT--Management
Jun 18, 2004
51
US
I have this select statment where I am selecting a bunch of fields and would like to set them all as variables. Originally I used a separate select statement for each field. This is my idea of how this should work, but id doesn't.

Dim connectionString As String = ("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.mappath("SupportRequests.mdb"))
Dim oleConnection As New OleDBConnection(connectionString)
oleConnection.Open()
Dim oleCommand = New OleDbCommand("Select firstname as fname, lastname as lname, hardware as hw, software as sw, problem as prob, importance as imp, barcode as barcode FROM requests where ticket = " & request.Querystring("id"))
oleCommand.Connection = oleConnection
fname = oleCommand.ExecuteScalar()
lname = oleCommand.ExecuteScalar()
hw = oleCommand.ExecuteScalar()
sw = oleCommand.ExecuteScalar()
prob = oleCommand.ExecuteScalar()
imp = oleCommand.ExecuteScalar()
barcode = oleCommand.ExecuteScalar()
oleConnection.Close()
 
First you'll need to Dim all of those variables. Then how about using a DataReader?
Dim reader as SqlDataReader = oleCommand.ExecuteReader(CommandBehavior.CloseConnection)
While reader.Read()
fname = reader("fname")
lname = reader("lname")
etc...........
Loop
 
Thanks, I tried that and this is the error I get


Exception Details: System.InvalidOperationException: ExecuteReader: Connection property has not been initialized.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top