drewsblues Posted November 25, 2003 Posted November 25, 2003 I'm getting errors when I try to do what (I think) is a pretty simple procedure: namely, retrieving records from an Access database with the OleDbDataReader object. Here's my code: Dim sPath As String = Server.MapPath("MyDb.mdb") Dim sConn As String = "Provider=Microsoft.Jet.OLEDB.4.0; DATA Source=" & sPath & ";" Dim sSql As String = "SELECT * FROM MyTable" Dim oConn As OleDbConnection Dim oCmd As OleDbCommand Dim oDr As OleDbDataReader oConn = New OleDbConnection(sConn) oConn.Open() oCmd = New OleDbCommand(sSql, oConn) oDr = oCmd.ExecuteReader(CommandBehavior.CloseConnection) While oDr.Read ... etc. ... End While oDr.Close() oConn.Close() The error I get is: Exception Details: System.Data.OleDb.OleDbException: No value given for one or more required parameters. It's complaining about the line that reads: oDr = oCmd.ExecuteReader(CommandBehavior.CloseConnection) Does anyone see any problems with the code I've written (it looks letter-perfect to me, but then I've been staring at my screen all day ;))? Advice is appreciated... Quote
Moderators Robby Posted November 25, 2003 Moderators Posted November 25, 2003 You need to execute the command object not the Closeconn Very important At the top of all your code pages place the following... Option Explicit On Option Strict On Quote Visit...Bassic Software
drewsblues Posted November 25, 2003 Author Posted November 25, 2003 Thanks for the quick response. Maybe I didn't follow you, but I get the same error even when I execute: oConn = New OleDbConnection(sConn) oConn.Open() oCmd = New OleDbCommand(sSql, oConn) oDr = oCmd.ExecuteReader() While oDr.Read() ... etc ... Is there some explicit syntax I'm missing? Quote
Muhad Posted November 26, 2003 Posted November 26, 2003 If found this code sample --> Dim myConnection As New OleDbConnection(myConnectionString) Dim myCommand As New OleDbCommand(mySelectQuery, myConnection) myConnection.Open() Dim myReader As OleDbDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection) While myReader.Read() Console.WriteLine(myReader.GetString(0)) End While myReader.Close() The only difference I see is that the Open() is after dimensioning the Command. Also have you tried removing CommandBehavior.CloseConnection ? Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.