Results 1 to 4 of 4

Thread: [RESOLVED] Store imported information into table...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Nov 2010
    Posts
    65

    Resolved [RESOLVED] Store imported information into table...

    OK so I have a .XML file and a DataBase.

    The specific form I am having trouble with is my Create New RepairOrder Form.

    I have 3 combo boxes, which I dragged onto the from the RepairOrder Table in my DataSet.

    Order Number (bound to the RO number from my imported .XML file)
    Customer (bound to my customers table)
    Vehicle ( bound to my vehicles table)

    at form load, I import the .XML file.

    Code:
    Private Sub FrmCreateOrder_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.ROTableAdapter.Fill(Me.BSMDataSet.RO)
            Me.VehicleTableAdapter.Fill(Me.BSMDataSet.Vehicle)
            Me.CustomerTableAdapter.Fill(Me.BSMDataSet.Customer)
            Me.RepairOrderTableAdapter.Fill(Me.BSMDataSet.RepairOrder)
            Dim BSMDataSet As New DataSet
    
            Dim filepath As String = "C:\color\PPGImport\PPGMixData.xml"
    
            BSMDataSet.ReadXml(filepath)
    
            Me.CBxROID.DataSource = BSMDataSet.Tables("RO")
    
            Me.RepairOrderBindingSource.AddNew()
        End Sub
    I should point out that BSMDataSet already exists and contains Tables identical to those I wish to import, but the debugger doesn't throw any exceptions when I run the form.

    Anyway, when the form loads everything looks right, all three comboboxes populate correctly.

    When I save my Repair Order, I want it to populate the RepairOrder Table. Currently, it tells me it has been saved, but doesn't update. Yet if I remove the binding to the table it's puilling from, I getthe message that Column RO_ID does not allow nulls.

    Please help

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,350

    Re: Store imported information into table...

    To be clear, you're trying to load existing data into the DataTable, then read the XML file into the DataTable and have that make appropriate changes to that existing data, then save those changes, right? In order to save changes back to the database, there have to actually be changes to save, i.e. the DataRows must have a RowState of something other than Unchanged. I've never really read data from an XML file into a DataTable before and I don't know what it does to RowStates. You would need it to set the RowState of any DataRows it updates to Modified but it may be that it leaves everything Unchanged. You can test that fairly easily by looking at the RowState of the DataRows after calling ReadXml.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Nov 2010
    Posts
    65

    Re: Store imported information into table...

    I figured it out, not sure if this is the best way of doing it but it works, so I'm happy lol.

    Instead of dragging the combobox from the table I wanted to fill, and then bining it to the source I wanted to get data from,

    I created the combobox from the source table, then added a textbox from the destination table and used the following code...

    Code:
        Private Sub ComboBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ComboBox.SelectedIndexChanged
            TextBox.Text = ComboBox.SelectedValue.ToString()
        End Sub

  4. #4
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,206

    Re: [RESOLVED] Store imported information into table...

    I should point out that BSMDataSet already exists and contains Tables identical to those I wish to import, but the debugger doesn't throw any exceptions when I run the form.
    The form load event doesn't throw an error many time even when there is one.

    You should put your code in a Try/Catch block,
    Code:
    Private Sub FrmCreateOrder_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Try
            Me.ROTableAdapter.Fill(Me.BSMDataSet.RO)
            Me.VehicleTableAdapter.Fill(Me.BSMDataSet.Vehicle)
            Me.CustomerTableAdapter.Fill(Me.BSMDataSet.Customer)
            Me.RepairOrderTableAdapter.Fill(Me.BSMDataSet.RepairOrder)
            Dim BSMDataSet As New DataSet
    
            Dim filepath As String = "C:\color\PPGImport\PPGMixData.xml"
    
            BSMDataSet.ReadXml(filepath)
    
            Me.CBxROID.DataSource = BSMDataSet.Tables("RO")
    
            Me.RepairOrderBindingSource.AddNew()
        Catch ex as Exception
            MessageBox.Show ex.ToString
        End Try
    End Sub

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