1

我正在使用 VB.Net,我有一个数据库包含两个表“Personne”和“PersonneCopy”(与 Personne 相同的架构 [4 列 = N°、FirstName、LastName、B_Day])

我在 Datagridview 中加载了第一个表,一切都很好,这是代码:

Dim Connection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= .\BD.mdb")
Dim SqlRequete As String = "Select * From Personne"
Dim Adapter As New OleDbDataAdapter(SqlRequete, Connection)
Dim DataSet As New DataSet
Adapter.Fill(DataSet, "Tb1")
Dim DataTable As New DataTable
DataTable = DataSet.Tables("Tb1")
DataGridView1.DataSource = DataTable

有什么方法可以将从 DataGridView1 中选择的整行添加到表“PersonneCopy”中?

顺便说一句,我用另一个 Datagridview 尝试了这段代码来获取所选行的索引并且它可以工作。

Dim Index As Integer = DataGridView1.Item(0, DataGridView1.CurrentRow.Index).Value
Dim SqlRequete As String = "Select * From Personne where N°=" & Index.ToString
Dim Adapter As New OleDbDataAdapter(SqlRequete, Connection)
Dim Ds As New DataSet
Adapter.Fill(Ds, "Tb")
DataGridView2.DataSource = Ds.Tables(0)
4

1 回答 1

1

像这样试试

Dim drCopy as DataRow
Dim tbCopy as Datatable 

tbCopy = .... 'PersonneCopy table

drCopy=tbCopy.NewRow()
For i as integer=0 to drCopy.columns.count-1
  drCopy(i)=Ds.Tables(0).rows(0).items(i)   '---------> or you can change rows(0)
Next
tbCopy.Rows.Add(drCopy)
于 2013-05-27T07:26:39.763 回答