Click to See Complete Forum and Search --> : MS Access table updation problem using ADO.Net


mahesh18
February 13th, 2003, 10:59 PM
Hi Everybody,
here i am doing one small database application using VB.NET and Ms-Access as a database.I am using the dataAdapter,dataSet of ADO.NET.
I am able to get all the records from the MS-Access table to the dataSet and i can delete a record which i want to delete.But i am not able to update the MS-Access table.
So that whatever changes i have done in dataset i am not able to get those changes in the Ms Access table where my data resides.
Please help me.Thanx in advance.

Regards
mahesh

gknierim
February 14th, 2003, 07:21 AM
Could you please post some code showing how you are deleting from the dataset and then updating the dataset?

Thanks,
Greg

mahesh18
February 14th, 2003, 07:50 AM
hi friend

here is the code


Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=D:\VB.Net\EmpData\EmpData.mdb")


Dim strQuery As String
strQuery = "select * from tblEmpData"
Dim objAdpter As New OleDb.OleDbDataAdapter(strQuery, conn)
Dim objDS As New DataSet("myDS")
objAdpter.Fill(objDS, "tblEmpData")
'conn.Close()

Dim objTable As DataTable
objTable = objDS.Tables("tblEmpData")

Dim objRow As DataRow
For Each objRow In objTable.Rows
If objRow.Item("id") = "5055" Then
objRow.Delete()
End If
Next

'For Each objRow In objTable.Rows
' MsgBox(objRow.Item("name"))
'Next

'Update the database.'''Problem is here
objAdpter.Update(objDS, "tblEmpData")


regards

mahesh

Iouri
February 14th, 2003, 07:56 AM
You have to create update commands

Private Sub btnUpdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpdate.Click

Dim sql As String = "SELECT * FROM Publishers"
Dim cn As New OleDbConnection(BiblioConnString)
Dim da As New OleDbDataAdapter(sql, cn)
Dim ds as New DataSet()

cn.Open()
da.Fill(ds, "Publishers")


Dim cmdBuilder As New OleDbCommandBuilder(da)


' generate the three default commands
da.DeleteCommand = cmdBuilder.GetDeleteCommand
da.InsertCommand = cmdBuilder.GetInsertCommand
da.UpdateCommand = cmdBuilder.GetUpdateCommand


'here modify your dataset. Do some changes like delete, insert.....


' Send changes them to the database.
da.Update(ds, "Publishers")
cn.Close()
End Sub

'ensure that changes were successful
If Not ds.HasChanges Then Exit Sub

'else there was no success give a message