Hello everyone
I'm using VB.Net and I have a database contains two tables "Personne" and "PersonneCopy" ( Same schema as Personne [4 columns = N°, FirstName, LastName, B_Day])
I load the first table in a Datagridview all it's fine with that, here's the code:

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

Is there any way to add the full row that was selected from DataGridView1 to the table "PersonneCopy"?

And by the way I tried this with an other Datagridview to get the index of the row selected and it works.

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)

So help please, thanks in advance.

5 Years
Discussion Span
Last Post by Neokyuubi

Is there any way to add the full row that was selected from DataGridView1 to the table "PersonneCopy"?

Yes. Get the value from datagrid and Use INSERT statement to add the selected row to Personnecopy table.


Thank you for the reply.
Well, yes Insert statement do the job when i had just 5 or 6 columns.
But when i had 20 or 25 columns , adding by an entire row using DATAROW it's more practical.
Now, i'm wondering what does "NewRow" of a Datatable do ?!

Using conn as New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source= .\BD.mdb")
Dim command As New OleDbCommand("Insert into table_Name (field1, field2, field3) values (@field1, @field2, @field3)", conn)

With command.Parameters
    .AddWithValue("@field1", datagridview1.rows(0).Item(0).Value)
    .AddWithValue("@field2", datagridview1.rows(0).Item(1).Value)
    .AddWithValue("@field3", datagridview1.rows(0).Item(2).Value)
End With

End Using

I hope you get the Idea :)

Edited by yvrej17


Thank you for the reply Yvrej17 ^^,
Nice it's basically what i have done, i wondered just about if i can copy the entire row at once, somehow with Datatable.Newrow.
Anyway i tested your methode and it works , i just changed



DataGridView1.Item(0, DataGridView1.CurrentRow.Index).Value

Cause Rows(index). has no item member.
The Parameters, this is new for me ^_^
Thank you.

Edited by Neokyuubi

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.