Click here to Skip to main content
15,902,636 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,
I am
I am trying to load my Datatable to a Dataset.This is wat i have done:
VB
Dim cmd As System.Data.OleDb.OleDbCommand = New System.Data.OleDb.OleDbCommand(strSQL, cn)
               Dim dr As System.Data.OleDb.OleDbDataReader = cmd.ExecuteReader()
               Dim dt As New Data.DataTable
               dt.Load(dr)
               Dim dsRet As DataSet = PCI_GetEmptyDataset()

               Dim dr1 As DataRow = dsRet.Tables("CSRSI_Import_Stage").NewRow()
               If (dt.Rows.Count > 0) Then
                   For Each row As DataRow In dt.Rows
                       Dim databasename As String = row.ItemArray(0).ToString()
                       dr1("Databasename") = databasename
                       dr1("DBAName") = row.ItemArray(1).ToString()
                       
                       dsRet.Tables("CSRSI_Import_Stage").Rows.Add(dr1)
                   Next

My Datatable has nearly 12000 rows. But after i load the first row i could not load the second row..I get this error "This row already belongs to this table"...Please help.
Thanks.
Posted
Comments
Richard C Bishop 29-Mar-13 11:05am    
You probably want to use an inrementer if you are not going to use a for loop. I would change the "1" in the row.ItemsArray() to an "i" and add i++; as the last line of your foreach loop.
ZurdoDev 29-Mar-13 11:12am    
You aren't calling NewRow each time.

1 solution

Move this line:
C#
Dim dr1 As DataRow = dsRet.Tables("CSRSI_Import_Stage").NewRow()
To be the first line in your loop.
 
Share this answer
 
Comments
vidkaat 29-Mar-13 12:09pm    
Thank u so much.
OriginalGriff 29-Mar-13 12:29pm    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900