none
Import row from one data table to another with Auto increment column in destination DT? RRS feed

  • Question

  • Hi,

    I am trying to import a row from one data table to another basically both data tables are same except one is a exported data table saved as XML so user can import part of the old data rows to new project. My data table has an auto increment column so xml also has these auto increment column. When importing rows to destination data table source auto increment column has a same id as destination one so i am getting error . How to ignore source values and auto increment with destination table?. 

            Dim num As Integer
    
            If Integer.TryParse(treeNode.Name, num) Then
    
                Dim dt = CType(EQ_BS.DataSource, DataTable) 'destination table
    
                Dim Row = ImportedDS.Tables(dtEquipment).Select("ID = " & num)(0) 'table imported from XML
                Row.Item(dtID) = Current_Selected_Node
                Row.Item(dtEQID) = ""                   'Autoincrement column 
    
                dt.ImportRow(Row)
    
            End If

    thanks

    Saturday, September 7, 2019 10:25 AM

Answers

  • Hallo,

    Thank forall the answers..i settled with following e.g code, may be not efficient as importrow but works.

    For Each dr As DataRow In sourceTable.Rows
        r = destinationTable.NewRow
        r("Name") = dr("Name")
        r("City") = dr("City")
        r("Cost") = dr("Cost")
        destinationTable.Rows.Add(r)
    Next 


    • Marked as answer by Shan1986 Monday, September 9, 2019 9:43 AM
    Sunday, September 8, 2019 7:48 AM

All replies