473,382 Members | 1,512 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Dataset.Update synchronization

Hi,

Consider the following scenario

I have a Database source i had filled in my dataset with the help of Dataadapter
after working on the dataset i want the data source to be updated back with the new data available with me.

It may be a small change in the employee_name column for example.

And if the data had already been modified even deleted by some other user of the database then my dataset update method will prone to some error.


How to synchronize the dataset with the datasource before updating the datasource.


Thanks,
Krish
Dec 8 '06 #1
1 1467
bhar
37
Hi,

Consider the following scenario

I have a Database source i had filled in my dataset with the help of Dataadapter
after working on the dataset i want the data source to be updated back with the new data available with me.

It may be a small change in the employee_name column for example.

And if the data had already been modified even deleted by some other user of the database then my dataset update method will prone to some error.


How to synchronize the dataset with the datasource before updating the datasource.


Thanks,
Krish

Hi,

a. Opening a Connection.
b. Instantiate the Commands.
c. Instantiate the DataAdapter.
d. Setting the DataAdapter command properties.

myAccountAdapter.SelectCommand = comAccountSelect
myAccountAdapter.InsertCommand = comAccountInsert
myAccountAdapter.DeleteCommand = comAccountDelete
myAccountAdapter.UpdateCommand = comAccountUpdate

e. Add Select Command parameters.
f. Add Insert Command parameters.
Ex:

comAccountInsert.Parameters.Add(“@id”, SqlDbType.Char, 6, “AccountCode”)
comAccountInsert.Parameters.Add(“@name”, SqlDbType.Char, 30, “AccountName”)

g.Add Update Command parameters.
h. Add Delete Command parameters.
i. Instantiate the DataSets.


When we are finished with manipulating data in the DataSet, it is time to update the DataSource. This is done using the Update method of the DataAdapter class. This method is responsible for examining the RowState property of each of the DataRow objects in the Rows collection. The Rows Collection is a member of each of the DataTable objects contained in the Tables collection of the dataset.


Private Sub UpdateDatabaseButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateDatabaseButton.Click
Dim i As Integer
myConnection.Open()
For i = 0 To (myAccountDataset.Tables(“AccountsTable”).Rows.Cou nt() - 1)
MsgBox(myAccountDataset.Tables(“AccountsTable”).Ro ws(i)(0))
MsgBox(myAccountDataset.Tables(“AccountsTable”).Ro ws(i)(1))
MsgBox(myAccountDataset.Tables(“AccountsTable”).Ro ws(i)(2))
MsgBox(myAccountDataset.Tables(“AccountsTable”).Ro ws(i)(3))
Next
myAccountAdapter.Update(myAccountDataset.GetChange s, “AccountsTable”)
End Sub
End Class

TRy this book Titled:"Database programming using vb.net and sqlserver"
[Link Removed]
Dec 11 '06 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Eric | last post by:
Hi, can anyone guide me throught this: In my application, I have a global DataSet. I then run FTP processes in up to 10 simultaneous threads and each thread calls progress events in the main...
6
by: Babu Mannaravalappil | last post by:
Can somebody please help me figure out why the following method exceptions out? Execution at the line marked with ********** hangs for about 15 seconds and then I get an error that says an...
10
by: localhost | last post by:
I have a static, thread-safe class with a DataSet as a property. When the class is instanced into an object, some callers add rows to a DataTable in the DataSet. Other callers read the DataSet. ...
2
by: Mojtaba Faridzad | last post by:
Hi, Please check these lines: DataSet dataSet = new DataSet(); dataAdapter.Fill(dataSet, "mytable"); DataRow row; row = dataSet.Tables.Rows; row.BeginEdit(); row = "555";
3
by: Moty Michaely | last post by:
Hello, I have an issue I would like to solve. I need a dataset synchronization mechanism method that needs to read data from SQL server and within an interval of time, read the data again and...
15
by: JIM.H. | last post by:
Hello, Can I send a dataset as a parameter into stored procedure and import data to a table in the stored procedure? Thanks, Jim.
9
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from...
12
by: Graham Blandford | last post by:
Hi all, Would someone be able to tell me the most 'graceful' way of removing unwanted rows from a dataset based on a condition prior to update? OR, resetting the rows all to unchanged after they...
22
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.