T
thomasp
Is there anyone that knows how to add a record to a MS Access database with
VB.NET. I have search for 3 days for some code that works. I have gathered
bits and pieces of code and put it together, but I have not found a solution
that works. If anyone has some code that works please reply.
Thanks
Thomas
The following gives an Invalid SQL Statement at: oAdapter.Update(ds,
"LCMR")
Dim oAdapter As OleDb.OleDbDataAdapter
Dim cb As OleDb.OleDbCommandBuilder
Dim dr As DataRow
Dim ds As DataSet
Dim strSQL As String = "Select * from LCMR"
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strAppPath & "TAM.mdb;Persist Security
Info=False"
ds = New DataSet()
oAdapter = New OleDb.OleDbDataAdapter(strSQL, strConn)
oAdapter.Fill(ds, "LCMR")
Try
dr = ds.Tables("LCMR").NewRow()
dr.BeginEdit()
dr("ID") = 1000
dr("ADate") = "6-JUN-5"
dr("ATime") = "01:00"
dr("POO") = strPOO
dr("POO_Alt") = 22
dr("POI") = strPOI
dr("POI_Alt") = 22
dr("Distance") = 1000
dr("Direction") = 100
dr("Target_NO") = "KT1001"
dr("Weapon Type") = "sasdf"
dr("Confirmed") = 1
dr.EndEdit()
ds.Tables("LCMR").Rows.Add(dr)
cb = New OleDb.OleDbCommandBuilder(oAdapter)
oAdapter.InsertCommand = cb.GetInsertCommand
oAdapter.Update(ds, "LCMR")
ds.AcceptChanges()
Catch oException As Exception
MessageBox.Show(oException.Message)
End Try
VB.NET. I have search for 3 days for some code that works. I have gathered
bits and pieces of code and put it together, but I have not found a solution
that works. If anyone has some code that works please reply.
Thanks
Thomas
The following gives an Invalid SQL Statement at: oAdapter.Update(ds,
"LCMR")
Dim oAdapter As OleDb.OleDbDataAdapter
Dim cb As OleDb.OleDbCommandBuilder
Dim dr As DataRow
Dim ds As DataSet
Dim strSQL As String = "Select * from LCMR"
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & strAppPath & "TAM.mdb;Persist Security
Info=False"
ds = New DataSet()
oAdapter = New OleDb.OleDbDataAdapter(strSQL, strConn)
oAdapter.Fill(ds, "LCMR")
Try
dr = ds.Tables("LCMR").NewRow()
dr.BeginEdit()
dr("ID") = 1000
dr("ADate") = "6-JUN-5"
dr("ATime") = "01:00"
dr("POO") = strPOO
dr("POO_Alt") = 22
dr("POI") = strPOI
dr("POI_Alt") = 22
dr("Distance") = 1000
dr("Direction") = 100
dr("Target_NO") = "KT1001"
dr("Weapon Type") = "sasdf"
dr("Confirmed") = 1
dr.EndEdit()
ds.Tables("LCMR").Rows.Add(dr)
cb = New OleDb.OleDbCommandBuilder(oAdapter)
oAdapter.InsertCommand = cb.GetInsertCommand
oAdapter.Update(ds, "LCMR")
ds.AcceptChanges()
Catch oException As Exception
MessageBox.Show(oException.Message)
End Try