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.

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")
conn.Open
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

command.ExecuteNonQuery()
command.Dispose()
conn.Close()
End Using

I hope you get the Idea :)

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.rows(0).Item(0).Value

to

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.