How to Insert recprd from datagrid to a table?

  • Thread starter Thread starter Mel
  • Start date Start date
M

Mel

Hi,

I created a form that would search a record from a table
and showed the details in datagrid. I have another button
that would insert the records showed in the datagrid to
another table..How will I do this?
 
Hi Mel

Are you talking about web or winform, the two datagrids are completly
different while using them is even more different.

Cor
 
Hi Mel,

I made a sample for you.
The begin is only to make the table.
In button1 is done as you said to select
In button2 is made the table, with one difference, I take the ones which are
not selected to make the sample more meaningful.

I hope this helps?

Cor
\\\Needs a datagrid and 2 buttons on a form
'The begin is to make the table
Dim dt As DataTable
Dim dv As DataView
Private Sub Form1_Load(ByVal sender As _
Object, ByVal e As System.EventArgs) Handles MyBase.Load
dt = New DataTable("Names")
dt.Columns.Add("IdName")
dt.Columns.Add("Name")
dt.Columns.Add("Country")
For i As Integer = 0 To 5
Dim dr As DataRow = dt.NewRow
dr(0) = i.ToString
dt.Rows.Add(dr)
Next
dt.Rows(0)(1) = "Herfried K. Wagner"
dt.Rows(1)(1) = "Armin Zingler"
dt.Rows(2)(1) = "Ken Tucker"
dt.Rows(3)(1) = "CJ Taylor"
dt.Rows(4)(1) = "Jay B. Harlow"
dt.Rows(5)(1) = "Cor Ligthert"
dt.Rows(0)(2) = "EU"
dt.Rows(1)(2) = "EU"
dt.Rows(2)(2) = "US"
dt.Rows(3)(2) = "US"
dt.Rows(4)(2) = "US"
dt.Rows(5)(2) = "EU"
DataGrid1.DataSource = dt
End Sub
'
'Here start the sample
Private Sub Button1_Click(ByVal sender _
As Object, ByVal e As System.EventArgs) Handles Button1.Click
dv = New DataView(dt)
dv.Sort = "Name"
dv.RowFilter = "Country = 'EU'"
DataGrid1.DataSource = dv
End Sub
Private Sub Button2_Click(ByVal sender As _
System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim dt2 As New DataTable("newnames")
dv.RowFilter = "Country = 'US'"
dt2 = dt.Clone
For Each drv As DataRowView In dv
dt2.ImportRow(drv.Row)
Next
DataGrid1.DataSource = dt2
///
 
Back
Top