Click to See Complete Forum and Search --> : error executereader


vbnov
February 18th, 2006, 10:31 AM
Dim objConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="path")
objConnection.Open()

rndnum = rnd(99999999)
sql1 = "SELECT OrderID FROM Orders WHERE Orders.OrderID = '" & rndnum & " ' "
Dim MyCommand As New OleDb.OleDbCommand(sql1, objConnection)
MyReader = MyCommand.ExecuteReader
MyReader.Read()

The above is the code . When i ran my app i got the foll error



Data type mismatch in criteria expression.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

Source Error:


Line 108: sql1 = "SELECT OrderID FROM Orders WHERE Orders.OrderID = '" & rndnum & " ' "
Line 109: Dim MyCommand As New OleDb.OleDbCommand(sql1, objConnection)
Line 110: MyReader = MyCommand.ExecuteReader
Line 111: MyReader.Read()


Please throw some ideas guys.thnx

jhammer
February 18th, 2006, 02:40 PM
What is the type of OrderId? If it is a number then the problem is the use of ' .
sql1 = "SELECT OrderID FROM Orders WHERE Orders.OrderID = '" & rndnum & " ' "

Try this:

sql1 = "SELECT OrderID FROM Orders WHERE Orders.OrderID = " & rndnum

The use of ' is for strings.

vbnov
February 20th, 2006, 01:36 PM
Thnx for the pointer. solved that problem

but the current error message is as follows

There is already an open DataReader associated with this Connection which must be closed first.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.

Source Error:


Line 111: sql1 = "SELECT OrderID FROM Orders WHERE Orders.OrderID = " & rndnum & " "
Line 112: Dim dbCommand As New OleDb.OleDbCommand(sql1, dbConnection)
Line 113: dbReader = dbCommand.ExecuteReader
Line 114: dbReader.Read()


Error at line 113

plz help to resolve this. thnx