Link to home
Start Free TrialLog in
Avatar of rohitnet100
rohitnet100

asked on

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 ?
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

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.
Avatar of rohitnet100
rohitnet100

ASKER

can you send me a sample code, how to do this?
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

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks.