none
vb.net problem dataset acceptchanges method not working: trying to delete a record on a

    Question

  • trying to delete a record in access backend table...

    The form shows the record being deleted..

    But the records in the table never get deleted. ?????

    Private

     

    Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click

     

    Dim intP As Integer

     

     

    Dim dav1 As DataView = New DataView(das1.Tables("tblMainData"))

    dav1.Sort =

    "MainTableID"

    intP =

    Me.BindingContext(das1, "tblMainData").Position.ToString()

     

     

    das1.Tables("tblMainData").Rows(intP).Delete()

     

    das1.Tables("tblMainData").AcceptChanges()

     

    dap1.Update(das1, "tblMainData")

     

    end sub

     

    Sorry for all the code:

    But here is all the code in the project...

    ================================================================================

     

    Dim das1 As New System.Data.DataSet()

     

    Dim dasComputer As New System.Data.DataSet()

     

    Dim cnn1 As New OleDb.OleDbConnection( _

     

    "Provider=Microsoft.Jet.OLEDB.4.0;" & _

     

    "Data Source=c:\Program Files\" & _

     

    "Crs_iCart\Beta_2010_Crs_iCart.mdb")

     

    Dim query As String = "SELECT * FROM tblMainData" ' Order By MainTableID DESC "

     

    Dim dap1 As New System.Data.OleDb.OleDbDataAdapter(query, cnn1)

     

    Tuesday, April 06, 2010 5:14 PM

Answers

  • Did you look in the documentation what function the method Acceptchanges has. 

    Remove it, then there is a chance that your code is working.

    I assume you need also before the update delete commands, but that can the commandbuilder do for you.

    So set before that update

    dim cmb as new OleDBCommandBuilder(Dap1)

    Then you don't have to ask your next question.


    Success
    Cor
    Tuesday, April 06, 2010 7:44 PM
  • Hi fordraiders,

    "You are calling AcceptChanges on your DataRow/DataTable/DataSet before you call Update on your DataAdapter or TableAdapter. AcceptChanges will commit all changes made since the data was loaded or since AcceptChanges was last called. This means that if you had a row that was marked as Modified, it will now be Unchanged. When you call Update, it will not recognize that the row has changes that need to be submitted to the database. The same applies for inserted and deleted rows as well. For more information, see the AcceptChanges documentation: http://msdn2.microsoft.com/en-us/library/system.data.dataset.acceptchanges.aspx. This applies to all database backends and application types (ASP.NET, Windows Forms, etc)."

    Please delete "das1.Tables("tblMainData").AcceptChanges()" statement.

    In additon, you need have the delete command before you do the update just as Cor mentioned.

    Please feel free to let us know if you have other questions.

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, April 09, 2010 6:04 AM

All replies

  • Did you look in the documentation what function the method Acceptchanges has. 

    Remove it, then there is a chance that your code is working.

    I assume you need also before the update delete commands, but that can the commandbuilder do for you.

    So set before that update

    dim cmb as new OleDBCommandBuilder(Dap1)

    Then you don't have to ask your next question.


    Success
    Cor
    Tuesday, April 06, 2010 7:44 PM
  • Hi fordraiders,

    "You are calling AcceptChanges on your DataRow/DataTable/DataSet before you call Update on your DataAdapter or TableAdapter. AcceptChanges will commit all changes made since the data was loaded or since AcceptChanges was last called. This means that if you had a row that was marked as Modified, it will now be Unchanged. When you call Update, it will not recognize that the row has changes that need to be submitted to the database. The same applies for inserted and deleted rows as well. For more information, see the AcceptChanges documentation: http://msdn2.microsoft.com/en-us/library/system.data.dataset.acceptchanges.aspx. This applies to all database backends and application types (ASP.NET, Windows Forms, etc)."

    Please delete "das1.Tables("tblMainData").AcceptChanges()" statement.

    In additon, you need have the delete command before you do the update just as Cor mentioned.

    Please feel free to let us know if you have other questions.

    Best regards,
    Alex Liang


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Friday, April 09, 2010 6:04 AM
  • @Alex,

    Don't take it to serious, the question states vb.net problem dataset acceptchanges method not working

    In my idea shows fordraiders that it is perfectly working, therefore I asked him to have a look himself in the documentation.

    Somehow this kind of statements gives me a bad feeling, the method acceptchanges is build by programmers. The method name is proven to be one of the most confusing ones Microsoft ever did. (Therefore has Linq SubmitChanges). But the programmer who had to make it, did something like it should.

    :-)



    Cor
    Friday, April 09, 2010 6:47 AM