ReadXML after File Copy

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Hans Munich

    #1

    ReadXML after File Copy

    Szenario:

    User selects a XML File ("products.xml" ) to import newest Data.
    Data should replace Data in an existing Acess File which is connected
    via Dataadapter (daadaptFLR). Bevore the Existing Data are deleted with
    RunSQL("DELETE * From Tbl_Fl_Rundleit ung").

    Function the Works:
    If I copy the File from the directory of the Application.exe then it
    works fine.

    Funktion Bugy:
    If I select the same file from another directory, the
    UpdateTable(dal Form.daadaptFLR , dsNew.Tbl_Fl_Ru ndleitung) Function
    fails. With following Error: Please remove Index or Constrains to
    prevent doubled Values. My Dataset seems to be loaded when i give it to
    a datagrid. And i can see a red attention hint with the same Error in
    first Line of Datagrid.

    I'll be thankfull for any kind of Help.

    Greetz from Munich



    Private Sub btOFD_Click(ByV al sender As System.Object, ByVal e As
    System.EventArg s) Handles btOFD.Click
    Dim ofd As New OpenFileDialog
    ofd.ShowDialog( )
    Try
    File.Copy(ofd.F ileName, Application.Sta rtupPath() +
    "\products.xml" , True)
    pnStatus.BackCo lor = System.Drawing. Color.Green
    Catch ex As Exception
    pnStatus.BackCo lor = System.Drawing. Color.Red
    End Try
    End Sub

    Private Sub checkGeneratedX ML()
    Dim dsNew As New dsPreise
    Dim dsHolder As New dsPreise
    Dim fstream As FileStream
    Dim dalForm As New frmPreise

    RunSQL("DELETE * From Tbl_Fl_Rundleit ung")
    RunSQL("DELETE * From Tbl_Flexibel")
    RunSQL("DELETE * From Tbl_Front_St_Md l")
    RunSQL("DELETE * From Tbl_Klm_Block")
    RunSQL("DELETE * From Tbl_Zubehoer")

    'DAten aus XML einlesen
    dsNew.Clear()
    dsNew.ReadXml(A pplication.Star tupPath() + "\products.xml" )
    'XmlReadMode.Di ffGram , XmlReadMode.Rea dSchema

    dgLoadTEst.Data Source = dsNew

    UpdateTable(dal Form.daadaptFLR , dsNew.Tbl_Fl_Ru ndleitung)
    UpdateTable(dal Form.daadaptFle xibel, dsNew.Tbl_Flexi bel)
    UpdateTable(dal Form.daadaptFro ntsteckmodul,
    dsNew.Tbl_Front _St_Mdl)

    'initSavedDetai lsList()

    'MsgBox("OK")
    'Return dsNew
    'End If
    End Sub

    Private Sub UpdateTable(ByV al daAdapt As Data.OleDb.OleD bDataAdapter,
    ByVal dt As DataTable)
    Dim ModifiedChildRe cords As DataTable = dt
    For Each ro As DataRow In dt.Rows
    'MsgBox(ro.RowS tate)
    Next
    Try
    If Not ModifiedChildRe cords Is Nothing Then
    daAdapt.Update( ModifiedChildRe cords)
    ModifiedChildRe cords.Dispose()
    End If
    Catch ex As Exception
    ' Update error, resolve and try again
    MsgBox("update Tab" + ex.Message + dt.TableName)
    End Try

    End Sub

  • Cor Ligthert [MVP]

    #2
    Re: ReadXML after File Copy

    Hans,

    From where you got that RunSQL I would expect OleDBcommand.ex ecutenonquery

    As well is my idea the command to remove all rows "Delete Table", I am not
    so sure however from Jet (access) in that..

    While this one will probably as well don't do very much well.
    ModifiedChildRe cords.Dispose()

    Or have you created your own wrapper and than we will find it of course
    never.

    I don't understand this.

    Cor
    ..
    "Hans Munich" <google@munixme mber.de> schreef in bericht
    news:1146751133 .923509.69200@g 10g2000cwb.goog legroups.com...[color=blue]
    > Szenario:
    >
    > User selects a XML File ("products.xml" ) to import newest Data.
    > Data should replace Data in an existing Acess File which is connected
    > via Dataadapter (daadaptFLR). Bevore the Existing Data are deleted with
    > RunSQL("DELETE * From Tbl_Fl_Rundleit ung").
    >
    > Function the Works:
    > If I copy the File from the directory of the Application.exe then it
    > works fine.
    >
    > Funktion Bugy:
    > If I select the same file from another directory, the
    > UpdateTable(dal Form.daadaptFLR , dsNew.Tbl_Fl_Ru ndleitung) Function
    > fails. With following Error: Please remove Index or Constrains to
    > prevent doubled Values. My Dataset seems to be loaded when i give it to
    > a datagrid. And i can see a red attention hint with the same Error in
    > first Line of Datagrid.
    >
    > I'll be thankfull for any kind of Help.
    >
    > Greetz from Munich
    >
    >
    >
    > Private Sub btOFD_Click(ByV al sender As System.Object, ByVal e As
    > System.EventArg s) Handles btOFD.Click
    > Dim ofd As New OpenFileDialog
    > ofd.ShowDialog( )
    > Try
    > File.Copy(ofd.F ileName, Application.Sta rtupPath() +
    > "\products.xml" , True)
    > pnStatus.BackCo lor = System.Drawing. Color.Green
    > Catch ex As Exception
    > pnStatus.BackCo lor = System.Drawing. Color.Red
    > End Try
    > End Sub
    >
    > Private Sub checkGeneratedX ML()
    > Dim dsNew As New dsPreise
    > Dim dsHolder As New dsPreise
    > Dim fstream As FileStream
    > Dim dalForm As New frmPreise
    >
    > RunSQL("DELETE * From Tbl_Fl_Rundleit ung")
    > RunSQL("DELETE * From Tbl_Flexibel")
    > RunSQL("DELETE * From Tbl_Front_St_Md l")
    > RunSQL("DELETE * From Tbl_Klm_Block")
    > RunSQL("DELETE * From Tbl_Zubehoer")
    >
    > 'DAten aus XML einlesen
    > dsNew.Clear()
    > dsNew.ReadXml(A pplication.Star tupPath() + "\products.xml" )
    > 'XmlReadMode.Di ffGram , XmlReadMode.Rea dSchema
    >
    > dgLoadTEst.Data Source = dsNew
    >
    > UpdateTable(dal Form.daadaptFLR , dsNew.Tbl_Fl_Ru ndleitung)
    > UpdateTable(dal Form.daadaptFle xibel, dsNew.Tbl_Flexi bel)
    > UpdateTable(dal Form.daadaptFro ntsteckmodul,
    > dsNew.Tbl_Front _St_Mdl)
    >
    > 'initSavedDetai lsList()
    >
    > 'MsgBox("OK")
    > 'Return dsNew
    > 'End If
    > End Sub
    >
    > Private Sub UpdateTable(ByV al daAdapt As Data.OleDb.OleD bDataAdapter,
    > ByVal dt As DataTable)
    > Dim ModifiedChildRe cords As DataTable = dt
    > For Each ro As DataRow In dt.Rows
    > 'MsgBox(ro.RowS tate)
    > Next
    > Try
    > If Not ModifiedChildRe cords Is Nothing Then
    > daAdapt.Update( ModifiedChildRe cords)
    > ModifiedChildRe cords.Dispose()
    > End If
    > Catch ex As Exception
    > ' Update error, resolve and try again
    > MsgBox("update Tab" + ex.Message + dt.TableName)
    > End Try
    >
    > End Sub
    >[/color]


    Comment

    • Hans Munich

      #3
      Re: ReadXML after File Copy

      What you are mssing is the following, and you are right.
      But it isnt my Problem, i think. The Problem is that it works completly
      with a file located in the same physikal directory as the executing
      Application. If my importet .xml File first is copied from another
      directory it fails.

      Public Sub RunSQL(ByVal sql As String)
      'SQL Befehl ausführen.
      Dim conn As New OleDbConnection (DBConnectionSt ring)
      Dim adapter As New OleDbDataAdapte r
      Try
      conn.Open()
      adapter.InsertC ommand = New OleDbCommand(sq l, conn)
      adapter.InsertC ommand.ExecuteN onQuery()
      conn.Close()
      Catch ex As Exception
      MsgBox(sql + "---" + ex.Message)
      End Try
      End Sub

      Comment

      • Cor Ligthert [MVP]

        #4
        Re: ReadXML after File Copy

        Hans,

        You write that you read it from the application folder, how you do that from
        another one?

        dsNew.ReadXml(A pplication.Star tupPath() + "\products.xml" )
        'XmlReadMode.Di ffGram , XmlReadMode.Rea dSchema

        Cor

        "Hans Munich" <google@munixme mber.de> schreef in bericht
        news:1146949733 .718015.302090@ j33g2000cwa.goo glegroups.com.. .
        What you are mssing is the following, and you are right.
        But it isnt my Problem, i think. The Problem is that it works completly
        with a file located in the same physikal directory as the executing
        Application. If my importet .xml File first is copied from another
        directory it fails.

        Public Sub RunSQL(ByVal sql As String)
        'SQL Befehl ausführen.
        Dim conn As New OleDbConnection (DBConnectionSt ring)
        Dim adapter As New OleDbDataAdapte r
        Try
        conn.Open()
        adapter.InsertC ommand = New OleDbCommand(sq l, conn)
        adapter.InsertC ommand.ExecuteN onQuery()
        conn.Close()
        Catch ex As Exception
        MsgBox(sql + "---" + ex.Message)
        End Try
        End Sub


        Comment

        • Hans Munich

          #5
          Re: ReadXML after File Copy

          With the File Copy Function...

          Private Sub btOFD_Click(ByV al sender As System.Object, ByVal e As
          System.EventArg s) Handles btOFD.Click
          Dim ofd As New OpenFileDialog
          ofd.ShowDialog( )
          Try
          File.Copy(ofd.F ileName, Application.Sta rtupPath() +
          "\products.xml" , True)
          pnStatus.BackCo lor = System.Drawing. Color.Green
          Catch ex As Exception
          pnStatus.BackCo lor = System.Drawing. Color.Red
          End Try
          End Sub

          Hans

          Comment

          • Cor Ligthert [MVP]

            #6
            Re: ReadXML after File Copy

            Hans,

            Are you sure you are not trying with this to copy the file to the area where
            the enduser has no rights to do. I would just change the path where you are
            reading and not use that application
            startuppath.

            This is normally the programdirector y Bin of your application, it should be
            a closed area.

            Just my idea

            Cor

            "Hans Munich" <google@munixme mber.de> schreef in bericht
            news:1147010516 .560300.13920@g 10g2000cwb.goog legroups.com...[color=blue]
            > With the File Copy Function...
            >
            > Private Sub btOFD_Click(ByV al sender As System.Object, ByVal e As
            > System.EventArg s) Handles btOFD.Click
            > Dim ofd As New OpenFileDialog
            > ofd.ShowDialog( )
            > Try
            > File.Copy(ofd.F ileName, Application.Sta rtupPath() +
            > "\products.xml" , True)
            > pnStatus.BackCo lor = System.Drawing. Color.Green
            > Catch ex As Exception
            > pnStatus.BackCo lor = System.Drawing. Color.Red
            > End Try
            > End Sub
            >
            > Hans
            >[/color]


            Comment

            Working...