Get only the rows changed from GridView then insert to database

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have a <asp:gridview/> that has a few columns editable. I need to capture
only the rows that were modified then insert
to database. Currently all my rows are getting updated since Im looping through all my results. How can I isolate the records that has changed and update them accordingly?

Im calling this from SubmitButtonClick() function
<div style="color:black; background-color:white
<pre> <span style="color:blue For <span style="color:blue Each grdVRow <span style="color:blue As GridViewRow <span style="color:blue In rsltGV.Rows

<span style="color:blue Using sqlConn <span style="color:blue As DbConnection = ......
<span style="color:blue Dim strUpd <span style="color:blue As <span style="color:blue String



<span style="color:blue Dim strID <span style="color:blue As <span style="color:blue String = rsltGV.DataKeys(grdVRow.RowIndex).Values(<span style="color:#a31515 "ID").ToString

<span style="color:blue Dim strFrstNm <span style="color:blue As <span style="color:blue String = rsltGV.DataKeys(grdVRow.RowIndex).Values(<span style="color:#a31515 "NAME").ToString

<span style="color:blue Dim str LstName <span style="color:blue As <span style="color:blue String = <span style="color:blue CType(grdVRow.FindControl(<span style="color:#a31515 "txtLastName"),TextBox).Text

<span style="color:blue Dim strAge <span style="color:blue As <span style="color:blue String = <span style="color:blue CType(grdVRow.FindControl(<span style="color:#a31515 "txtAge"),TextBox).Text


updSqlStr ="UPDATE TABLE <span style="color:blue SET... ID=strID, FIRST_NM =strFrstNm......
....
....
.... Execute Update

<span style="color:blue End <span style="color:blue Using

<span style="color:blue Next
[/code]


<br/>

View the full article
 
Back
Top