save new rows in grid

how can i insert only new rows from grid into database and only update the existing rows.
how to find which is new and which are existing rows ?
rohitnet100Asked:
Who is Participating?
 
CodeCruiserCommented:
If you are saving the grid contents manually then you can use the primary key to determine if its an existing record or new one.
0
 
Carl TawnSystems and Integration DeveloperCommented:
If you are updating using something like a DataAdapter then you just call the Update() method passing it your DataSet/DataTable. The DataAdapter will figure out for itself which rows require inserts and which require updates.
0
 
rohitnet100Author Commented:
can you send me a sample code, how to do this?
0
 
Carl TawnSystems and Integration DeveloperCommented:
Very simplisticly:
Dim cn As New SqlConnection("Your connection string")
Dim adap As New SqlDataAdapter("SELECT SomeColumns FROM SomeTable", cn)

Dim dt As New DataTable()
adap.Fill(dt)

'// add some rows, change some rows, etc

'// commit the changes
adap.Update(dt)

Open in new window

0
 
rohitnet100Author Commented:
Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.