'how to move the datagridview record value column to another record column and then save it into the database in the vb.net

how to move the datagridview record value column to another record column and then save it into the database in the vb.net. What I mean as follows is move the record value from the column "CIU" to the column "CIUB" and move the record value from the column "DPR" to the column "DPRB" and below I attach the screenshot I want with yellow marking. What is the best way to recommend?.I want to do it with the event button

 Dim Path As String = Environment.CurrentDirectory
    Dim cn As String = "provider=Microsoft.Jet.OLEDB.4.0; data source=" & Path & "; Extended Properties=dBase IV"
    Dim source1 As New BindingSource()
    Private Sub fillDataGridView1()
        Try
            Dim query As String = "SELECT * FROM GSDTS WHERE QTY > 0"
            Using con As OleDbConnection = New OleDbConnection(cn)
                Using cmd As OleDbCommand = New OleDbCommand(query, con)
                    'cmd.Parameters.AddWithValue("@PNM", ComboBox1.SelectedValue)
                    Using da As New OleDbDataAdapter(cmd)
                        Dim dt As DataTable = New DataTable()
                        da.Fill(dt)
                        da.Dispose()
                        source1.DataSource = dt
                        'Me.DataGridView1.DataSource = dt
                        Me.DataGridView1.DataSource = source1
                        Me.DataGridView1.Refresh()
                    End Using
                End Using
            End Using
        Catch ex As Exception
        End Try
    End Sub
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        fillDataGridView1()
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try
            connectionString = cn
            con = New OleDbConnection(connectionString)
            con.Open()
            Dim sql As String = "UPDATE GSDTS SET CIUB = CIU, CIU = NULL WHERE QTY > 0"
            cmd = New OleDbCommand(sql, con)
            'cmd.Parameters.AddWithValue("@CODE", ComboBox1.SelectedValue)
            cmd.ExecuteNonQuery()
            con.Close()
            Me.fillDataGridView1()
        Catch myerror As OleDbException
            MessageBox.Show("Error: " & myerror.Message)
        Finally
        End Try
    End Sub
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        For Each row As DataRow In source1.Rows
            row("CIUB") = row("CIU")
            row("CIU") = DBNull.Value
        Next
    End Sub

thanks jack ORIGINAL IN DATAGRIDVIEW DESIRED RESULT IN DATAGRIDVIEW



Solution 1:[1]

What you're describing has nothing at all to do with the grid. That's for the user. You can just do it in the BindingSource or the DataTable. It's a simple loop:

For Each row As DataRow In myDataTable.Rows
    row("CIUB") = row("CIU")
    row("CIU") = DBNull.Value
    '...
Next

In fact, you don't even need to retrieve any data because you can do it all in SQL on the database:

UPDATE GSDTS
SET CIUB = CIU, CIU = NULL
WHERE QTY > 0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 user18387401