Thomas,
What error are you getting? I would guess that it would be a syntax
error in the insert command as you have fields that have spaces in the names
or are reserved words. To get around that error set the QuotePrefix and
QuoteSuffix properites of the CommandBuilder to "[" and "]" respectively or
both to "`". Other errors may be caused by the table not having a
PrimaryKey. You can try FillSchema first if the table has a primary key
defined in Access. If not you will have to specify which field is the
PrimaryKey.
You may get faster answers in microsoft.public.dotnet.framework.adonet.
Ron Allen
<th*****@msala.net> wrote in message
news:42***********************@news.newsdemon.com. ..
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
--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access