Results 1 to 4 of 4

Thread: copy datarow in other datatable

Threaded View

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 1999
    Location
    Belgium
    Posts
    98

    copy datarow in other datatable

    Hi,

    I am trying to create a procedure that can copy datarows in other datatables. I have a dataset with one datatable and this datatable contains 10 datarows. I want to create 10 seperate datasets each containg one datatable. This datatable contains only one datarow. This datarow should be a copy of the datarow in the first datatable (the one with the 10 datarows).

    Thanks for reading my problem.

    This is my test code, but it does not work.

    Code:
            'connection class 
            Dim c As New clsSQLConnection("localhost", "northwind", "sa", "sa")
            'dataset class 
            Dim d As New clsSQLDataset(c)
            'fill the dataset 
            d.fillDataset(Chr(34) & "sales by year" & Chr(34) & " '1990', '2004'")
            'a new collection 
            Dim coll As New Collection
    
            Dim tmpDS As DataSet
            Dim tmpTable As DataTable
            Dim tmpRow As DataRow
    
    
            For Each dr As DataRow In d.dtSet.Tables(0).Rows
    
                tmpDS = New DataSet
                tmpTable = New DataTable
                tmpTable.Rows.Add(dr)
                'An unhandled exception of type 'System.ArgumentException' 
                'occurred in system.data.dll
                'Additional information: 
                'This row already belongs to another table. 
                tmpDS.Tables.Add(tmpTable)
                coll.Add(tmpDS)
            Next
    
            MsgBox(coll.Count)
    Last edited by R@emdonck; Mar 15th, 2004 at 06:40 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width