Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I'm trying to have my form load a table depending on the date, much like a calendar. I'm getting this error An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll

 

Here is the code

 

Dim con_str1 As New OleDbConnection("Provider =_

Microsft.Jet.OLEDB.4.0;" & "Data Source =_ C:\data\database.mdb")

 

Dim pCmd As New OleDbCommand("SELECT * FROM TABLE", con_str1)

con_str1.Open()

Dim myReader As OleDbDataReader = pCmd.ExecuteReader()

 

 

Try

While myReader.Read()

lbx1.FindString(myReader.GetInt32(0).ToString() + ", " _

+ myReader.GetString(1))

End While

Finally

' always call Close when done reading.

myReader.Close()

' always call Close when done reading.

con_str1.Close()

End Try

 

It halts at con_str1.Open()

  • *Experts*
Posted

Is there supposed to be an underscore in the Data Source part of your connection string?

 

-nerseus

"I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
  • *Experts*
Posted

I'm no DB expert, but it looks like you have some multi-line

characters in the connection string, which are taken literally as a

string when enclosed in quotes.

 

Also, you don't need the concatenation operator (&) to combine

two constant strings (their values are hard-coded).

 

That being said, try this on for size:

Dim con_str1 As New OleDbConnection("Provider = Microsft.Jet.OLEDB.4.0;Data Source = C:\data\database.mdb")

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

  • *Experts*
Posted
So, did that solve your problem? :confused:

"Being grown up isn't half as fun as growing up

These are the best days of our lives"

-The Ataris, In This Diary

Posted

Code again

 

This produces the same error.

 

 

Dim con_str1 As New OleDbConnection("Provider = Microsft.Jet.OLEDB.4.0;Data Source = C:\data\20304aa1.mdb")

Dim pCmd As New OleDbCommand("SELECT * FROM April", con_str1)

con_str1.Open()

Dim myReader As OleDbDataReader = pCmd.ExecuteReader()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...