Skip to main content

DataRowStates of DataSet

Programmers always look for shortcuts and ease while he perform his job. Microsoft provides a number of Services in this Regard. VisualStudio.NET is one of the remarkable development of Microsoft. (Enough to talk about Microsoft)

Here, I want to tell you that how can we get only that data from DataSet which we manipulate while we were performing our job.

DataSet has a number of DataRowState Properties:

1) DataRowState.Added
2) DataRowState.Deleted
3) DataRowState.Modified
4) DataRowState.Detached
5) DataRowState.Unchanged

DataRowState help us in getting the manipulated data which we either Change, Delete or Add.

Now, How can we use these state. I am telling you below but first we have to fill a dataset by any values. For Example, I create my own database. Insert values in it and after then I call them through query into dataset.

Here, I assume that you must have fill your dataset already. Now change a value of any row from your dataset. To get confirmation that something is changed you can use the below command:


If it return you "True" then we get confirmed that something is modified in dataset. Now you can get all the changes either modified rows, added rows, deleted rows, etc. by single command


or you can get only those deleted/Modified/Added rows by following the below code:


The above command will return you only updated rows.

Below I am writing entire Code for the easiness of your sake:

/////////////Form Loaded Method//////////////////////
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles

da = New SqlDataAdapter("select * from tblstudent_Main", con)
da.Fill(ds, "table1")
ds.Tables(0).Rows(1).Item(1) = "Zeeshan"
ds.Tables(0).Rows(5).Item(1) = "Ahmed"
Dim dr As DataRow
dr = ds.Tables(0).NewRow
dr.Item(0) = 7
dr.Item(1) = "Memon"
Catch ex As Exception

End Try
End Sub

//////////Button Click Method/////////////////
Dim ds2 As New DataSet
ds2 = ds.GetChanges()
For Each dr As DataRow In ds2.Tables(0).Rows
///Return True if the rows are added else False


//Return you DataRowState. Remember if you do not write toString() then
it will return you numeric value.


DataGridView1.DataSource = ds2.Tables(0)

MessageBox.Show("transfereed successfully")

I hope that this will help you alot in understanding the DataRowState Concept.


Popular posts from this blog

The sign-in method you're trying to use isn't allowed. For more info, contact your network administrator

Above problem occur when you have not added a group (of which User try to login)  in your local policy login. To resolve the issue, follow the steps,
Log in as the administrator on the server, then start the Group Policy Management Editor by running the  gpmc.msc command from PowerShell or the Command Line window. 1. In the Group Policy Management window on the left hand side, select Group Policy Management. 2. Click to expand the  Forest tree node.
3. Click Domains.
4. Select your domain name.
5. Click Group Policy Objects. 6. In the right-hand window, double-click Default Domain Controllers Policy.
7. Right-click Default Domain Controllers Policy and Select Edit.
8. In the Group Policy Management Editor window, click Default Domain Controllers Policy.
9. Click Computer Configuration, and then click Policies.
10. Click Windows Settings, and then click Security Settings. 11. Click Local Policies and then click User Rights Assignments.
12. In the right pane, click Allow log on locally. 12. Cli…

ORA-38104: Columns referenced in the ON Clause cannot be updated

In my case, this error pertains to Oracle Merge query. After 30 minutes of time wastage and a lot of hunting on different forums, I come to know that where and why was my merge query throwing exception.

I was giving multiple criteria in ON clause of merge query, and was also trying to update a column which I have mentioned in ON clause. Once I remove that column from update clause of merge query, it executed successfully.

I hope that this will also works for you.

In case if this post help you, then please comment on it.


Cannot use the special principal 'sa'. (Microsoft SQL Server, Error: 15405)

Yesterday, I start SQL Server 2005 and try to connect with sa user but was enable to connect with the 'sa' user and got this error:

Cannot use the special principal 'sa' (Microsoft SQL Server, Error: 15405)After doing some google, I found out the solution which I am sharing so that others can get all the possible solutions from this article.
The titled message mean that your sa user is disabled. To enable it, you have to follow below mentioned steps:1) you have to change the authentication mode: go to Management Studio and open Object Explorer. Connect to your server and right-click on the server name, then select Properties. Go to Security tab and under Server Authentication select "SQL Server and Windows Authentication Mode".2) Also, after you follow the directions above, you will also need to explicitly enable the sa account as well. Go to Security->Logins. Right-click on the "sa" account, select "Properties". In the list on the lef…