我正在使用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)
答案 0 :(得分: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)