Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / VB.NET / May 2006

Tip: Looking for answers? Try searching our database.

ReadXML after File Copy

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Hans Munich - 04 May 2006 14:58 GMT
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_Rundleitung").

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(dalForm.daadaptFLR, dsNew.Tbl_Fl_Rundleitung) 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(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btOFD.Click
       Dim ofd As New OpenFileDialog
       ofd.ShowDialog()
       Try
           File.Copy(ofd.FileName, Application.StartupPath() +
"\products.xml", True)
           pnStatus.BackColor = System.Drawing.Color.Green
       Catch ex As Exception
           pnStatus.BackColor = System.Drawing.Color.Red
       End Try
   End Sub

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

       RunSQL("DELETE * From Tbl_Fl_Rundleitung")
       RunSQL("DELETE * From Tbl_Flexibel")
       RunSQL("DELETE * From Tbl_Front_St_Mdl")
       RunSQL("DELETE * From Tbl_Klm_Block")
       RunSQL("DELETE * From Tbl_Zubehoer")

       'DAten aus XML einlesen
       dsNew.Clear()
       dsNew.ReadXml(Application.StartupPath() + "\products.xml")
'XmlReadMode.DiffGram , XmlReadMode.ReadSchema

       dgLoadTEst.DataSource = dsNew

       UpdateTable(dalForm.daadaptFLR, dsNew.Tbl_Fl_Rundleitung)
       UpdateTable(dalForm.daadaptFlexibel, dsNew.Tbl_Flexibel)
       UpdateTable(dalForm.daadaptFrontsteckmodul,
dsNew.Tbl_Front_St_Mdl)

       'initSavedDetailsList()

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

 Private Sub UpdateTable(ByVal daAdapt As Data.OleDb.OleDbDataAdapter,
ByVal dt As DataTable)
       Dim ModifiedChildRecords As DataTable = dt
       For Each ro As DataRow In dt.Rows
           'MsgBox(ro.RowState)
       Next
       Try
           If Not ModifiedChildRecords Is Nothing Then
               daAdapt.Update(ModifiedChildRecords)
               ModifiedChildRecords.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] - 05 May 2006 09:23 GMT
Hans,

From where you got that RunSQL  I would expect OleDBcommand.executenonquery

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.
  ModifiedChildRecords.Dispose()

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

I don't understand this.

Cor
.
> Szenario:
>
[quoted text clipped - 80 lines]
>
>    End Sub
Hans Munich - 06 May 2006 22:08 GMT
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(DBConnectionString)
       Dim adapter As New OleDbDataAdapter
       Try
           conn.Open()
           adapter.InsertCommand = New OleDbCommand(sql, conn)
           adapter.InsertCommand.ExecuteNonQuery()
           conn.Close()
       Catch ex As Exception
           MsgBox(sql + "---" + ex.Message)
       End Try
   End Sub
Cor Ligthert [MVP] - 07 May 2006 05:59 GMT
Hans,

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

    dsNew.ReadXml(Application.StartupPath() + "\products.xml")
'XmlReadMode.DiffGram , XmlReadMode.ReadSchema

Cor

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(DBConnectionString)
       Dim adapter As New OleDbDataAdapter
       Try
           conn.Open()
           adapter.InsertCommand = New OleDbCommand(sql, conn)
           adapter.InsertCommand.ExecuteNonQuery()
           conn.Close()
       Catch ex As Exception
           MsgBox(sql + "---" + ex.Message)
       End Try
   End Sub
Hans Munich - 07 May 2006 15:01 GMT
With the File Copy Function...

Private Sub btOFD_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btOFD.Click
       Dim ofd As New OpenFileDialog
       ofd.ShowDialog()
       Try
           File.Copy(ofd.FileName, Application.StartupPath() +
"\products.xml", True)
           pnStatus.BackColor = System.Drawing.Color.Green
       Catch ex As Exception
           pnStatus.BackColor = System.Drawing.Color.Red
       End Try
   End Sub

Hans
Cor Ligthert [MVP] - 07 May 2006 16:15 GMT
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 programdirectory Bin of your application, it should be
a closed area.

Just my idea

Cor

> With the File Copy Function...
>
[quoted text clipped - 12 lines]
>
> Hans

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.