Assign HasChanges For Each Row In A Datagrid

wahoud

New member
Joined
Jan 15, 2004
Messages
4
Hi There
I Have A Datagrid That I Use To Fill An Invoice With ItemID, Description,Qunty,Price.

Saving And Retrieving The Invoice to and from SQL Server Is POC

How Can I Mark The Modification On Each row Or a Deleted Row , So That When I Save My Work The Software Would Recognise The Update That Has Been Done And Perform The Condition Given Correctly
my Condition In My Code That I Have Assigned In The Save Mode Are

Code:
For Each row In InvDataSet1.Tables(0).Rows
                Assign Values To All Parameters And Excute Querry
                With MyComm
                    .Parameters("@InvNum").Value = CInt(txtInvID.Text)
                    .Parameters("@ItemID").Value = row.Item(1)
                    .Parameters("@InvQunty").Value = row.Item(2)
                    .Parameters("@ItemPrice").Value = row.Item(3)
                    .Parameters("@InvVAT").Value = row.Item(4)
                End With
                If row.RowState = DataRowState.Added Then
                   MyComm.CommandText = "NewInvLine"
                ElseIf row.RowState = DataRowState.Modified Then
                    MyComm.CommandText = "UpdateInvLine"
                ElseIf row.RowState = DataRowState.Deleted Then
                    MyComm.CommandText = "DeleteInvLine"
                ElseIf row.RowState = DataRowState.Unchanged Then
                    MyComm.CommandText = "UpdateInvLine"
                End If
                MyComm.ExecuteNonQuery()
[\Code]
Thank You In Advance 
 :confused:
 
Instead of all that messing around, why not just use a data adapter that has all commands assigned. Then a call to the Update method of data adapter will pick the correct command automatically AND set the RowState of your row.

If you want to stick to your current method, a quick look at the members of the DataRow class would have revealed the AcceptChanges method.
 
Back
Top