H
Hans Munich
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
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