troubleshooting Question

Copy table in access database

Avatar of packman25
packman25 asked on
Visual Basic.NET
3 Comments1 Solution435 ViewsLast Modified:
I need to copy a table into a new table.  I need to copy the data and the structure of the table.
I have tried using a command to create the new table but it does not copy my primary key.  When i try to update the new table i get an error because the table does not have a primary key.

 This is the command i use to copy the table
Dim cmd1 As New OleDb.OleDbCommand("SELECT * INTO " & newTable & " From " & oldTable)

        sql = "Select * from " & newTable
        da = New OleDb.OleDbDataAdapter(sql, con)
        Dim ds As New DataSet
        Dim dt As New DataTable

        da.Fill(ds, "newPart")
        DataGrid1.DataSource = ds
        Dim cb As New OleDb.OleDbCommandBuilder(da)

        ds.Tables("newPart").Rows(0).Item("PO_Number") = Convert.ToInt32(txtPO.Text)
        ds.Tables("newPart").Rows(0).Item("Rec_Date") = pickDate.Text
        ds.Tables("newPart").Rows(0).Item("Quantity") = Convert.ToInt32(txtQty.Text)
        ds.Tables("newPart").Rows(0).Item("consignment") = True
        ds.Tables("newPart").Rows(0).Item("Num_Samples") = Convert.ToInt32(txtNumSamp.Text)

         da.Update(ds, "newPart")
after i try the update i get this error:

 dynamic sql generation for the UpdateCommad is not supported against a selectCommand that does not return any key column information
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros