DataSet.AcceptChanges not working

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pushpendra vats

    DataSet.AcceptChanges not working

    Hi!!,

    I have created a dataadapter and datasdet through code .On
    button i have added two records in dataset and called
    acceptchanges method. on second button i am inserting the
    records in database with the helpof update method of
    dataadapter. But no records are inserted.Now if i remove
    the dataset.acceptc hanges method then it starts adding the
    records.....
    what could be the problem....
    code follows......

    Thanks
    Pushpendra

    Dim da As New OleDb.OleDbData Adapter("select * from
    test", "Provider=SQLOL EDB;Data Source=192.168. 16.4;Initial
    Catalog=Northwi nd;user id=sa;password= ;")
    Dim myConnection As New OleDb.OleDbConn ection
    ("Provider=SQLO LEDB;Data Source=192.168. 16.4;Initial
    Catalog=Northwi nd;user id=sa;password= ;")
    Dim dt As DataTable
    Dim dr As DataRow
    Dim ds As New DataSet()

    Private Sub Form1_Load(ByVa l sender As System.Object,
    ByVal e As System.EventArg s) Handles MyBase.Load
    da.Fill(ds, "test")


    End Sub

    Private Sub Button1_Click(B yVal sender As
    System.Object, ByVal e As System.EventArg s) Handles
    Button1.Click
    dt = ds.Tables("test ")
    da.InsertComman d = New OleDb.OleDbComm and("insert
    test values('" + TextBox1.Text + "','" + TextBox2.Text
    + "')", myConnection)


    Dim i As Integer
    dr = dt.NewRow()
    dr("name") = TextBox1.Text
    dr("address") = TextBox2.Text

    dt.Rows.Add(dr)
    ds.acceptchange s()
    MsgBox(dt.Rows. Count())
    End Sub

    Private Sub Button2_Click(B yVal sender As
    System.Object, ByVal e As System.EventArg s) Handles
    Button2.Click
    Try

    da.Update(ds, "test")
    MsgBox("Record saved")
    Catch er As Exception
    MsgBox(er.ToStr ing)
    End Try
    End Sub
  • Cor Ligthert

    #2
    Re: DataSet.AcceptC hanges not working

    For the ones who are intrested I have answered this question in the original
    thread with this

    The acceptchanges is to prevent updating.
    It stands for Accept the changes as if you did the updating.

    Cor






    Comment

    • Cor Ligthert

      #3
      Re: DataSet.AcceptC hanges not working

      For the ones who are intrested I have answered this question in the original
      thread with this

      The acceptchanges is to prevent updating.
      It stands for Accept the changes as if you did the updating.

      Cor






      Comment

      Working...