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
extraction of objects from a sharepoint content database
Using a geometry type check constrint in sql sever 2008
After update subform, then update the main form field
How can I return an error message when a field or control is Blank
Some Excel 2007 worksheets open with blue screen (previous thread no help)
In Access 2007,
Loop through each table, then Find & Replace
Blocking Skype on ISA 2004
Authoritative restore - -windows 2008
Outlook 2007 Language Issue