Cannot initialize OleDbDataReader object

G

Guest

When stepping thru the code of this app, it will jump completely over the line that delcares the data reader object.. Does anyone know why

Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=c:\todo.mdb
Dim myCommand As New OleDbCommand(
Dim myreader As OleDbDataReade
Dim myConn As New OleDbConnection(myConnString

Tr
myCommand.Connection = myCon
myConn.Open(
myCommand.CommandText = "Select * From names
myreader = myCommand.ExecuteReader(
While myreader.Read(
End Whil
myConn.Close(
Catch eException As Exceptio
MsgBox(eException.ToString
End Tr

Pressing F8 will step me thru every line but will jump right over the "Dim mreader as OleDbDataReader"
 
M

Marina

The debugger does not stop at variable declarations, unless that variable is
being initialized at declaration time.

Jeremy Doucet said:
When stepping thru the code of this app, it will jump completely over the
line that delcares the data reader object.. Does anyone know why?
Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;User
ID=Admin;Data Source=c:\todo.mdb"
Dim myCommand As New OleDbCommand()
Dim myreader As OleDbDataReader
Dim myConn As New OleDbConnection(myConnString)

Try
myCommand.Connection = myConn
myConn.Open()
myCommand.CommandText = "Select * From names"
myreader = myCommand.ExecuteReader()
While myreader.Read()
End While
myConn.Close()
Catch eException As Exception
MsgBox(eException.ToString)
End Try

Pressing F8 will step me thru every line but will jump right over the "Dim
mreader as OleDbDataReader"
 
J

Jeremy Doucet

I see. Well, do you know why I can't get that code to run? I've tried
using the OleDBDataAdapter instead of the reader with this code:

Try
Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;User
ID=Admin;Data Source=c:\ToDo.mdb"
Dim conn As OleDbConnection = New
OleDbConnection(myConnString)
Dim sqlStr As String = "SELECT * FROM Names"
' Create data adapter object
Dim da As OleDbDataAdapter = New OleDbDataAdapter(sqlStr,
conn)
Dim ds As DataSet = New DataSet()
da.Fill(ds, "Listing")
Catch eException As Exception
MsgBox(eException.ToString)
End Try

and I get the same error on there. As soon as it gets to the da.Fill
line, the next thing it does is throw an exception. Same thing on the
previous code.
 
M

Marina

It's really hard to say, seeing as how you never actually said what the
exception was.
 
G

Guest

The error I am getting is this: UNSPECIFIED ERROR: E_FAIL. I have even tried changing the code again. Here is my new code:

Imports System
Imports System.Data
Imports System.OleDB

Try
Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;user id=admin;password=;Data Source=c:\\ToDo.mdb;Persist Security Info=False"
Dim conn As OleDbConnection = New OleDbConnection(myConnString)
Dim myname As String
conn.Open()
Dim sqlStr As String = "SELECT * FROM Names"
' ' Create data adapter object
Dim myCommand As New OleDbCommand(sqlStr, conn)
myCommand.Connection = conn
Dim myNewReader As OleDbDataReader = myCommand.ExecuteReader


conn.Close()
Catch myException As Exception
MsgBox(myException.Message)
End Try


End Sub
 
C

Cor

Hi Jeremy,

I think that it is because it is VB and not C# there is a little error in
your connection string (C# notation), I also would try it with the most
simple string.

Dim myConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=c:\ToDo.mdb;"

I think the problem is those double //.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top