update record count

xswzaq

Well-known member
Joined
Jul 9, 2007
Messages
61
Programming Experience
Beginner
VB.NET:
Private Sub RCUTsaveBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RCUTsaveBtn.Click
        conn.Open()
        Try
            'Command run if save sucessfully
            Dim myCommand As OracleClient.OracleCommand
            Dim ra As Integer
            For i As Integer = 0 To Me.DataGrid.Rows.Count - 2
                myCommand = New OracleClient.OracleCommand("UPDATE  TABLE1 SET CAUSE = '" & Me.DataGrid.Rows(i).Cells("CAUSE").Value & "' WHERE  NO = '" & Me.DataGrid.Rows(i).Cells("NO").Value & "'", conn)
                ra = myCommand.ExecuteNonQuery()
            Next
         MessageBox.Show("Save Successful! Records Affect: " & ra, "ASO TAG DTL", MessageBoxButtons.OK, MessageBoxIcon.Information)
   Catch ex As Exception
            'Error message catch when update cannot be save
            MessageBox.Show("Unable to Save! " & ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
        conn.Close()
    End Sub

I got this code above to work fine, but one problem I am having is this code (i think, but I am not sure)

VB.NET:
MessageBox.Show("Save Successful! Records Affect: " & ra, "ASO TAG DTL", MessageBoxButtons.OK, MessageBoxIcon.Information)

No matter how many records it update, it only said Save Sucessful! Records Affect: 1. But I know there are at least more than one is update. Please guide me to right direction. Thank you very much.
 
Well you do not update ra at all (except for the 1st time).
The ExecuteNonQuery always returns true/1 and you just assign 1 to ra and nothing else !!!

Try this:

VB.NET:
Dim ra As Integer
            For i As Integer = 0 To Me.DataGrid.Rows.Count - 2
                myCommand = New OracleClient.OracleCommand("UPDATE  TABLE1 SET CAUSE = '" & Me.DataGrid.Rows(i).Cells("CAUSE").Value & "' WHERE  NO = '" & Me.DataGrid.Rows(i).Cells("NO").Value & "'", conn)
                myCommand.ExecuteNonQuery()
                ra +=1
            Next
 
thank you very much, this is exactly what i want. I have another question to ask but don't want to create a new thread. Is there a way to not allows users to add new row in the datagrid? They can edit/modifier the existing rows, but not allow to add new row.
 
Back
Top