selecting rows in a datagridview

JohnDW

Well-known member
Joined
Jun 13, 2012
Messages
60
Location
Antwerp, Belgium
Programming Experience
1-3
I have a code that relates to a datagridview (dgv2).
This code runs through the records of the DGV and it is intended that the code works with the
records that has the value "voucher" in cell (4).
As the code works now he walks through all records.
I'm tried for a code that selected the rows from the DGV
where cell (4) is "voucher" .
the stored procedure ("DELDossiersKK") can remove then the rows from another table
(related at the value "voucher").
For Example : If there are 4 rows in the DGV and 3 from the rows have the
value "voucher" in cells(4), then the code
has to delete 3 rows in another table with the stored procecure "DelDossiersKK".
VB.NET:
Dim vProductName As String = "voucher"
        Dim I As Integer
        For I = 0 To DGV2.Rows.Count - 1
            If vProductName = CStr(DGV2.Rows(I).Cells(4).Value) Then   
                'Here the code should select Rows in the DGV2 with "voucher" as value in cells(4)
                
                Dim SQL As String = "StoredProcedureNextNumber"  
                'This is a Stored Proc that gets the highestnumber from a table that must be deleted bij the Stored Proc "DelDossiersKK"
                Dim NextNumber As Integer = 0 
                Dim CMD1 As New SqlCommand(SQL, MyConnection)
                CMD1.CommandType = CommandType.StoredProcedure
                Dim outputValue As New SqlParameter("@NextNumber", SqlDbType.Int)
                
                outputValue.Direction = ParameterDirection.Output
                
                CMD1.Parameters.Add(outputValue)
                
                
                MyConnection.Open()
                On Error Resume Next
                CMD1.ExecuteNonQuery()
                MyConnection.Close()
               
                NextNumber = CInt(CMD1.Parameters("@NextNumber").Value)
                If vProductId = CStr(DGV2.Rows(I).Cells(4).Value) Then
                    Dim SQL4 As String = "DelDossiersKK"
                    Dim CMD7 As New SqlCommand(SQL4, MyConnection)
                    CMD7.CommandType = CommandType.StoredProcedure
                   
                    
                    CMD7.Parameters.AddWithValue("@NextNumber", NextNumber)
                   
                    MyConnection.Open()
                    On Error Resume Next
                    CMD7.ExecuteNonQuery()
                    MyConnection.Close()
                   
                Else
                    End
                End If
            End If
        Next
How to do this?
Txs,
John
 
Back
Top