Row Already belongs to this table.

I have a page with a button that when clicked this code fires. All I am trying to do is add all the rows from a datatable to a access database.
I can add one new row but when I add the second new row I get the error row already belongs to this table
Here's the code:
Dim row As Integer
        Dim dtCertificates As New DataTable
        Dim TempCerts As DataTable
        Dim drNewRow2 As DataRow = dtCertificates.NewRow
        cn1ADOconnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Inetpub\wwwstalsmanna\Databases\inventory.MDB"
        cn1ADOconnection.Open()
        daData1Adapter = New OleDb.OleDbDataAdapter("Select * From  [inventory]  where [VendorName] =   '" & ddlVendors.Text & "'  ", cn1ADOconnection)
        cb1CommandBuilder = New OleDb.OleDbCommandBuilder(daData1Adapter)
        daData1Adapter.Fill(dtCertificates)
        dtCertificates.Clear()
        'Add the certificates to inventory
        row = 0
        TempCerts = CType(Session("NewInventory"), DataTable)
        While row < TempCerts.Rows.Count
            With drNewRow2
                drNewRow2("VendorName") = TempCerts.Rows(row)(0)
                drNewRow2("certificatenumber") = TempCerts.Rows(row)(3)
                drNewRow2("CertificateValue") = Val(TempCerts.Rows(row)(1))
                drNewRow2("PurchaseDate") = txtPurchaseDate.Text
                drNewRow2("entereddate") = Today
                drNewRow2("Certificatetype") = TempCerts.Rows(row)(2)
                drNewRow2("EnteredBy") = User.Identity.Name
            End With
            dtCertificates.Rows.Add(drNewRow2)
            daData1Adapter.Update(dtCertificates)
            row = row + 1
        End While
whiwexAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Guy Hengel [angelIII / a3]Billing EngineerCommented:
just move the = dtCertificates.NewRow from the variable declaration to the loop body:

Dim row As Integer
        Dim dtCertificates As New DataTable
        Dim TempCerts As DataTable
        Dim drNewRow2 As DataRow
        cn1ADOconnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\Inetpub\wwwstalsmanna\Databases\inventory.MDB"
        cn1ADOconnection.Open()
        daData1Adapter = New OleDb.OleDbDataAdapter("Select * From  [inventory]  where [VendorName] =   '" & ddlVendors.Text & "'  ", cn1ADOconnection)
        cb1CommandBuilder = New OleDb.OleDbCommandBuilder(daData1Adapter)
        daData1Adapter.Fill(dtCertificates)
        dtCertificates.Clear()
        'Add the certificates to inventory
        row = 0
        TempCerts = CType(Session("NewInventory"), DataTable)
        While row < TempCerts.Rows.Count
            drNewRow2 = dtCertificates.NewRow
            With drNewRow2
                drNewRow2("VendorName") = TempCerts.Rows(row)(0)
                drNewRow2("certificatenumber") = TempCerts.Rows(row)(3)
                drNewRow2("CertificateValue") = Val(TempCerts.Rows(row)(1))
                drNewRow2("PurchaseDate") = txtPurchaseDate.Text
                drNewRow2("entereddate") = Today
                drNewRow2("Certificatetype") = TempCerts.Rows(row)(2)
                drNewRow2("EnteredBy") = User.Identity.Name
            End With
            dtCertificates.Rows.Add(drNewRow2)
            daData1Adapter.Update(dtCertificates)
            row = row + 1
        End While
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
whiwexAuthor Commented:
Thanks
That was it.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.