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 ?
Who is Participating?
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.
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.
rohitnet100Author Commented:
can you send me a sample code, how to do this?
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()

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

'// commit the changes

Open in new window

rohitnet100Author Commented:
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.