PC Review


Reply
Thread Tools Rate Thread

DataSet.AcceptChanges not working

 
 
pushpendra vats
Guest
Posts: n/a
 
      8th Apr 2004
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.acceptchanges method then it starts adding the
records.....
what could be the problem....
code follows......

Thanks
Pushpendra

Dim da As New OleDb.OleDbDataAdapter("select * from
test", "Provider=SQLOLEDB;Data Source=192.168.16.4;Initial
Catalog=Northwind;user id=sa;password=;")
Dim myConnection As New OleDb.OleDbConnection
("Provider=SQLOLEDB;Data Source=192.168.16.4;Initial
Catalog=Northwind;user id=sa;password=;")
Dim dt As DataTable
Dim dr As DataRow
Dim ds As New DataSet()

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


End Sub

Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button1.Click
dt = ds.Tables("test")
da.InsertCommand = New OleDb.OleDbCommand("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.acceptchanges()
MsgBox(dt.Rows.Count())
End Sub

Private Sub Button2_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
Button2.Click
Try

da.Update(ds, "test")
MsgBox("Record saved")
Catch er As Exception
MsgBox(er.ToString)
End Try
End Sub
 
Reply With Quote
 
 
 
 
Cor Ligthert
Guest
Posts: n/a
 
      8th Apr 2004
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






 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What does DataSet.AcceptChanges do? Ronald S. Cook Microsoft ADO .NET 2 28th Jul 2007 09:06 AM
InRowChangingEventException from DataSet.AcceptChanges Michael Freidgeim Microsoft ADO .NET 0 17th Nov 2005 12:21 AM
DataSet.AcceptChanges? Christopher Weaver Microsoft C# .NET 4 20th May 2005 09:41 PM
dataSet acceptChanges =?Utf-8?B?cy1nYWxpdA==?= Microsoft Dot NET 4 28th Sep 2004 11:11 AM
what does the Acceptchanges() method of the dataset do? Juan Romero Microsoft ADO .NET 6 11th Sep 2003 03:44 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:55 AM.