Insert into MS-Access table does not work

M

Manfred

Hi all

I don't understand why the following sample won't work.

I added a tableadapter with drag and drop from the datasource which is a
MS-Access DB and try to insert a record. The record is in the dataset
but never gets inserted in the access db.


Me.Tabelle1TableAdapter.Fill(Me.Db6DataSet.Tabelle1)
Dim drnew As DataRow
drnew = Db6DataSet.Tabelle1.NewRow
drnew("Testfeld") = "MyTestStringToInsert"
Db6DataSet.Tabelle1.Rows.Add(drnew)
Tabelle1TableAdapter.Update(Db6DataSet.Tabelle1)


Regards

Manfred
 
E

eswar.net

Manfred said:
Hi all

I don't understand why the following sample won't work.

I added a tableadapter with drag and drop from the datasource which is a
MS-Access DB and try to insert a record. The record is in the dataset
but never gets inserted in the access db.


Me.Tabelle1TableAdapter.Fill(Me.Db6DataSet.Tabelle1)
Dim drnew As DataRow
drnew = Db6DataSet.Tabelle1.NewRow
drnew("Testfeld") = "MyTestStringToInsert"
Db6DataSet.Tabelle1.Rows.Add(drnew)
Tabelle1TableAdapter.Update(Db6DataSet.Tabelle1)


Regards

Manfred
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Hello Manfred,my name is Eswar and i am working as a programmer in
dotnet.
Add a 'CommandBuilder' object of connection type you have used. As
dim cb as new OledbCommandBuilder(Me.Tabelle1TableAdapter)
and

Try this code.
Me.Tabelle1TableAdapter.Fill(Me.Db6DataSet.Tabelle1)
Dim drnew As DataRow
drnew = Db6DataSet.Tabelle1.NewRow
drnew("Testfeld") = "MyTestStringToInsert"
Db6DataSet.Tabelle1.Rows.Add(drnew)
Me.Tabelel1TableAdapter.InsertCommand=cb.GetInsertCommand() ( I added this line)
Tabelle1TableAdapter.Update(Db6DataSet.Tabelle1)

Note: After doing any modification you have to get the command of that
type by using CommandBuilder object and then call the "Update()"
command of table adapter.
Have a nice day
 

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