Microsoft
Software
Hardware
Network
Question : Getting a First Chance Exception when trying to add a record to access with VB.NET
Hello all! I am getting the following error in my Immediate window:
A first chance exception of type 'System.Data.OleDb.OleDbEx
ception' occurred in System.Data.dll
A first chance exception of type 'System.Data.OleDb.OleDbEx
ception' occurred in System.Data.dll
A first chance exception of type 'System.Data.OleDb.OleDbEx
ception' occurred in System.Data.dll
A first chance exception of type 'System.Data.OleDb.OleDbEx
ception' occurred in System.Data.dll
A first chance exception of type 'System.Data.OleDb.OleDbEx
ception' occurred in System.Data.dll
A first chance exception of type 'System.Data.OleDb.OleDbEx
ception' occurred in System.Data.dll
That's not repeated - I get the error 6 times every time i run the program.
My Code is as follows:
Public Function AddToDB(ByRef Table As String, ByRef DBColumnName As String, ByVal ValueToWrite As String) As String
Try
Dim con As New OleDb.OleDbConnection
Dim ds As New DataSet
Dim da As OleDb.OleDbDataAdapter
Dim sql As String
Dim dsNewRow As DataRow
Dim ex As OleDb.OleDbException
con.ConnectionString = "Provider=Microsoft.Jet.OL
EDB.4.0;" & _
"Data Source=C:\saw.mdb;Jet OLEDB:Database Password=hello;"
sql = "SELECT * FROM " & Table
da = New OleDb.OleDbDataAdapter(sql
, con)
da.Fill(ds, Table)
Dim cb As New OleDb.OleDbCommandBuilder(
da)
dsNewRow = ds.Tables(Table).NewRow()
dsNewRow.Item("Date_Time")
= DateTime.Now()
dsNewRow.Item(DBColumnName
) = ValueToWrite
ds.Tables(Table).Rows.Add(
dsNewRow)
da.Update(ds, Table)
con.Close()
con = Nothing
da = Nothing
ds = Nothing
dsNewRow = Nothing
sql = Nothing
da = Nothing
AddToDB = ValueToWrite & ": Written to DB"
Catch ex As Exception
'Error Handeling
AddToDB = "Database Write Error" & ex.ToString()
End Try
The correct data is entered in the correct table every time, I just don't know why this error is being thrown. I have been searching for while on how to resolve this with no luck. Thanks!
Answer : Getting a First Chance Exception when trying to add a record to access with VB.NET
You're DataAdapter has no UpdateCommand, hence nothing to do when you call da.Update().
Random Solutions
active directory, W2k8 R2 DC, Kerberos failures, Event ID: 3, 4771, 4769, 4768, 4776, 4625 source: Microsoft Windows security
Date Format problem in Microsoft Access 2000
Out of resources error when moving lots of files
problem opening word attachment with XP professional
SCCM 2007 Constant Despooler error 4406
access 2003 parse data length undetermined
referencing form variables in adp views
Flash will only work when I run IE in admin mode
Changing DNS address of Netowork interface Card using windows script.
to_date MS-Access