Click here to Skip to main content
15,904,287 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends i want to update multiple rows at time

Here is my code
VB
Dim a As Integer
                   Dim alar As New ArrayList
                   For a = 0 To DataGridView1.Rows.Count - 1
                       If DataGridView1.Rows(a).Cells(0).Selected = True Then

                           alar.Add(DataGridView1.Rows(a).Cells("cardno").Value)

                           DataGridView2.Rows.Add(DataGridView1.Rows(a).Cells(0).Value, DataGridView1.Rows(a).Cells(1).Value, DataGridView1.Rows(a).Cells(2).Value, DataGridView1.Rows(a).Cells(3).Value, DataGridView1.Rows(a).Cells(4).Value)
                       End If

                   Next
                   '--------------------------------------------------
                   Dim count As Integer = alar.Count

                   Dim dsfs = alar.Item(0).ToString
                   '---------------------------------------------------
                   For i = 0 To alar.Count - 1

                       dsfs = alar.Item(0).ToString
                       Dim cn As New OleDbConnection
                       Dim cmd As New OleDbCommand

                       cn.ConnectionString = My.Settings.trialConnectionString
                       cn.Open()
                       cmd.Connection = cn
                       cmd.CommandType = CommandType.Text
                       ' For i = 0 To DataGridView1.Rows.Count - 1
                       Dim ab As String
                       ab = DataGridView1.CurrentRow.Cells("cardno").Value
                       cmd.CommandText = "update voter set Castt='" & ToolStripComboBox1.Text & "' where cardno= '" & alar.Item(0).ToString & "'"
                       cmd.ExecuteNonQuery()

                       ' Next
                       cn.Close()
                   Next
                   If res > 0 Then
                       MsgBox("Record  Not Update")
                       al.Clear()
                   Else
                       MsgBox("Record  Update")
                   End If
                   'End If
                   '---------------Roemove selected row int gridview------------------'
                   Dim row As Integer
                   Dim selRow As New DataGridViewRow
                   Dim index As Integer
                   index = DataGridView1.SelectedRows.Item(0).Index
                   selRow = DataGridView1.Rows.Item(index)
                   DataGridView1.Rows.Remove(selRow)
                   row = row - 1

               End If
               ' MsgBox("Allocate Voter to " + ToolStripComboBox1.Text)
           End If



In this code only one record will update

Please help me........

Thanks in advance.......
Posted

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900