copy row

ss123

Member
Joined
Feb 25, 2006
Messages
14
Programming Experience
1-3
does anyone know how to copy the selected row of data from one table (access) and insert to another table? ie. in one form, i have 2 data grid (A and B) for different table, i want to click on the row in A then insert to B and show it, can it be done? Please advice. Thank you.
 
You are basically adding a new row to the underlying table of datagrid B.
I use Component One datagrids so the code needs to be altered as how you access the values for Grid A.
You are transfering values field to field. The fields are defined in the .xsd file for the dataset. You are adding a row to dataset B and filling it with the values from the current record of dataset A.

sample Code:

VB.NET:
            Try
                Me.BindingContext(DsDataSetB1, "TableName").EndCurrentEdit()
            Catch eEndEdit As System.Exception
                System.Windows.Forms.MessageBox.Show(eEndEdit.Message)
            End Try

            Dim tblTableB As DataTable
            tblTableB = DsDataSetB1.Tables("TableName")
            Dim drRowB As DataRow
            drRowB  = tblTableB.NewRow()
            ' Set the DataRow field values as necessary.
            drRowB ("NewField1") = [COLOR=Green]'value in grid A column1[/COLOR]
            drRowB ("NewField2") = [COLOR=Green]'value in grid A column2[/COLOR]
            drRowB ("NewField3") = [COLOR=Green]'value in grid A column3[/COLOR]
            drRowB ("NewField4") = [COLOR=Green]'value in grid A column4[/COLOR]
            tblTableB.Rows.Add(drRowB )
Sorry about not providing the crutial code for 'value in grid A column1.
For my ComponentOne datagrid I get to use GridA.Columns("Field1").Value

Hope this helps anyway.

 
Back
Top