An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in system.data.dll

B

barret bonden

I get :"An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll" at line
"Dim rec As Integer = cmd.ExecuteNonQuery()" when running:

Dim cs As String
cs = "Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=C:\backup\laptop\debt\benifits.mdb;Mode=ReadWrite|Share Deny None;"

Dim cn As New OleDbConnection(cs)

cn.Open()

' Dim sql As String = "insert into t (first,last) values
('tom','jefferson')"

Dim sql As String = "insert into t (first) values ('tom')"

Dim cmd As New OleDbCommand

cmd.Connection = cn

cmd.CommandText = sql

Dim rec As Integer = cmd.ExecuteNonQuery()

'cmd.ExecuteNonQuery()

'Debug.WriteLine(rec)

cn.Close()


this from page 725"programming MS vb net." MS press. I do note that I
finally got something working ! the code below runs !!!!
'page 708 MS programming ms vb net balena

'Ok connected mode skip with console write

Dim con1 As New ADODB.Connection

con1.Open("Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data
Source=C:\backup\laptop\debt\benifits.mdb;Mode=ReadWrite|Share Deny None;")

Dim r1 As New ADODB.Recordset

Dim s1 As String

'r1.Open("select * from benifits", con1, ADODB.CursorTypeEnum.adOpenKeyset,
ADODB.LockTypeEnum.adLockOptimistic)

r1.Open("select * from t", con1, ADODB.CursorTypeEnum.adOpenKeyset,
ADODB.LockTypeEnum.adLockOptimistic)

Do Until r1.EOF

s1 = r1("first").Value

' Console.WriteLine(r1("creditors").Value)

Console.WriteLine(s1)

r1.MoveNext()

Loop

r1.Close()

con1.Close()

I have no idea why the book goes from ADOB connection to Oledb connections
I wish someone would invent Dbase for windows- something simple and
effective.
 
V

Val Mazur \(MVP\)

Hi,

Do you have a try catch section, that catches exceptions? If yes, then you
could check exception to see actual error message. I am suspecting that
FIRST field name causes it. I believe FIRST is a reserved word and you need
to wrap it into square brackets
 
B

barret bonden

that was it. very kind of you; thanks - at this rate I'll be writing useful
apps in a just a few years ....
I'll keep at it.
 

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