none
Dataset and XML RRS feed

  • Question

  • Hi,

    Im using this code to put xml into dataset and load it to SQL Server Database(table)

    dim Infods As New DataSet("Info DataSet")
     Infods.ReadXml(String.Format("{0}\Info.xml", systemfilepath)) 
    dim _guid as System.Guid = System.Guid.NewGuid
        Dim connection As SqlConnection = New SqlConnection(My.Settings.CollectorConnectionString)
        Dim sbc As SqlBulkCopy = New SqlBulkCopy(connection)
        'I NEED TO INSER 2 ADDITIONAL COLUMNS
        Infods.Tables(0).Columns.Add("CollectedZipID", GetType(System.Guid))
        Infods.Tables(0).Columns.Add("CollectedFileName", GetType(System.String))
        sbc.DestinationTableName = "MachineInfo"
        sbc.ColumnMappings.Add("MachineName", "MachineName")
        sbc.ColumnMappings.Add("MachineUserName", "MachineUserName")
        sbc.ColumnMappings.Add("OSVersion", "OSVersion")
        sbc.ColumnMappings.Add("BootTime", "BootTime")
        sbc.ColumnMappings.Add("DSXUtils", "DSXUtils")
        sbc.ColumnMappings.Add("EffectPatterns", "EffectPatterns")
        sbc.ColumnMappings.Add("CollectedZipID", "CollectedZipID")
        sbc.ColumnMappings.Add("CollectedFileName", "CollectedFileName")
        connection.Open()
        sbc.WriteToServer(Infods.Tables(0))
        connection.Close()
    

    Now i need to insert 2 Additional Columns "CollectedZipID" and "CollectedFileName" that are not in xml or in that dataset.Ok that isn't problem "Infods.Tables(0).Columns.Add("CollectedZipID", GetType(System.Guid))...." but i also need to insert in those 2 columns N values(depending how much rows are in dataset table) that are not in xml or in that dataset (one is string that i will get from other source and one is Guid) and then insert that dataset in sql table.i know that somehow i need to loop for each row..some help would be greate.

    thanks

    Tuesday, September 14, 2010 6:53 PM

Answers

  • Hi Danijel,

    As for this scenario, I think you need to add the two columns to the datatable, then loop through all the rows of the datatable and adding values to the two columns of each row with values from the Guid and filename, something like:

    Infods.Tables(0).Columns.Add("CollectedZipID", GetType(System.Guid))
    Infods.Tables(0).Columns.Add("CollectedFileName", GetType(System.String))

    ......

    For Each row As DataRow In Infods.Tables(0).Rows
         row("CollectedZipID") = _guid 
         row("CollectedFileName") = _fileNameFromOpenFileDialog 
    Next

    ......

    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, September 20, 2010 8:50 AM
    Moderator

All replies

  • Hi Danijel,

    So you already have the columns "CollectedZipID" and "CollectedFileName" in your sql server table ? On which part you need help, how to insert values into these two columns of dataset(datatable) ? If so, where's the data source for these two columns ?

    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Thursday, September 16, 2010 3:55 AM
    Moderator
  • Hi Alex,

    Yes those 2 colums are already in sql table.

    Yes i need help how to insert values for those 2 columns that i have created columns in dataset.before i insert whole dataset in sql table.

    i don't have datasource (dataset,datatable,array) for those 2 columns.

    For Column CollectedZipID i will generate System.Guid.NewGuid.

    For Column CollectedFileName i will get filename from OpenFileDialog.

    So the problem is how to insert those 2 values in those 2 columns on existing dataset DataSet("Info DataSet") that is created via function "ReadXml".

     

    Thanks,

    Danijel

    Sunday, September 19, 2010 9:59 AM
  • Hi Danijel,

    As for this scenario, I think you need to add the two columns to the datatable, then loop through all the rows of the datatable and adding values to the two columns of each row with values from the Guid and filename, something like:

    Infods.Tables(0).Columns.Add("CollectedZipID", GetType(System.Guid))
    Infods.Tables(0).Columns.Add("CollectedFileName", GetType(System.String))

    ......

    For Each row As DataRow In Infods.Tables(0).Rows
         row("CollectedZipID") = _guid 
         row("CollectedFileName") = _fileNameFromOpenFileDialog 
    Next

    ......

    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, September 20, 2010 8:50 AM
    Moderator
  • Hi Danijel,

    I am writting to follow up the thread. Does the above suggestion work ?

    Please feel free to let me know if you need help.

    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, September 27, 2010 3:52 AM
    Moderator
  • Hi Danijel,

    I am marking the reply as answer. Please feel free to let me know if you need help.

    Best regards,

    Alex Liang

    MSDN Subscriber Support in Forum

    If you have any feedback on our support, please contact msdnmg@microsoft.com


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, October 6, 2010 7:48 AM
    Moderator