CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2002
    Location
    india
    Posts
    31

    MS Access table updation problem using ADO.Net

    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

  2. #2
    Join Date
    Jan 2000
    Posts
    264
    Could you please post some code showing how you are deleting from the dataset and then updating the dataset?

    Thanks,
    Greg

  3. #3
    Join Date
    Oct 2002
    Location
    india
    Posts
    31
    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

  4. #4
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878
    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
    Iouri Boutchkine
    [email protected]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured