-
error executereader
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
-
Re: error executereader
What is the type of OrderId? If it is a number then the problem is the use of ' .
Code:
sql1 = "SELECT OrderID FROM Orders WHERE Orders.OrderID = '" & rndnum & " ' "
Try this:
Code:
sql1 = "SELECT OrderID FROM Orders WHERE Orders.OrderID = " & rndnum
The use of ' is for strings.
-
Re: error executereader
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