xml 2 sql

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Good Morning,

Ok here is what I am trying to accomplish I have 12 xml files that I want to
load into a sqlce database. At the end of step 2 if I look at

dsTraker.tables(i).rows.count

I see the correct number of records(rows) for that table.

But at the end of this code the database exists but no tables or data.

Any ideas on where I have gone wrong

Thank you

chuck

Dim aXMLFiles As Array
Dim aXSDFiles As Array
Dim i, x As Integer
Dim xsdpath As String

Step 1 find all of my xml files load into a array

If File.Exists(gDataPathPda & "sinventry.xml") Then
aXMLFiles = Directory.GetFiles(gDataPathPda, "*.xml")
Array.Sort(aXMLFiles)
else
MsgBox("You need to do a sync", MsgBoxStyle.Critical, "Missing data
files")
End If

If File.Exists(gDataPathPda & "sinventry.xsd") Then
aXSDFiles = Directory.GetFiles(gDataPathPda, "*.xsd")
Array.Sort(aXSDFiles)
else
MsgBox("You need to do a sync", MsgBoxStyle.Critical, "Missing data
files")
End If


Step 2 Load a dataset with all of the data from the xml files

Dim xmlpath As String
i = UBound(aXMLFiles) + 1
Try
For x = 1 To i
Dim tempDS As New DataSet
xmlpath = aXMLFiles.GetValue(x - 1).ToString
Dim tablename As String
tablename = tempDS.Tables.Item(0).TableName
xmlpath = aXMLFiles.GetValue(x - 1).ToString
xsdpath = aXSDFiles.GetValue(x - 1).ToString
dsTraker.ReadXmlSchema(xsdpath)
dsTraker.ReadXml(xmlpath)
Next
Catch ex As FormatException
End Try

Step 3 Connect to the sqlce database

If File.Exists("\Windows\TrakerData.sdf") Then
File.Delete("\Windows\TrakerData.sdf")
End If
Dim SqlCeEngine As SqlCeEngine
SqlCeEngine = New SqlServerCe.SqlCeEngine
SqlCeEngine.LocalConnectionString =
"Provider=Microsoft.SQLSERVER.OLEDB.CE.2.0; data
source=\Windows\TrakerData.sdf"
SqlCeEngine.CreateDatabase()
Dim cn As SqlCeConnection

Try
cn = New SqlCeConnection
cn.ConnectionString = "data source=\Windows\TrakerData.sdf"
If cn.State = ConnectionState.Open Then
cn.Close()
End If
cn.Open()
Catch sqlex As SqlCeException
Dim SqlErr As SqlCeError
For Each SqlErr In sqlex.Errors
MessageBox.Show(SqlErr.Message)
Next
Catch ex As Exception
End Try

Step 4 Fill database with the dataset using the update method of the
dataadapter

Dim myDataAdapter As New SqlCeDataAdapter
Try
myDataAdapter.TableMappings.Add("sbcdefs", "sbcdefs")
myDataAdapter.TableMappings.Add("scustomers", "scustomers")
myDataAdapter.TableMappings.Add("sinbndlst", "sinbndlst")
myDataAdapter.TableMappings.Add("sinbound", "sinbound")
myDataAdapter.TableMappings.Add("sinventry", "sinventry")
myDataAdapter.TableMappings.Add("slineitem", "slineitem")
myDataAdapter.TableMappings.Add("slookups", "slookups")
myDataAdapter.TableMappings.Add("snextone", "snextone")
myDataAdapter.TableMappings.Add("sproducts", "sproducts")
myDataAdapter.TableMappings.Add("sshipping", "sshipping")
myDataAdapter.TableMappings.Add("ssystrakr", "ssystrakr")
myDataAdapter.TableMappings.Add("suserdefs", "suserdefs")
myDataAdapter.Update(dsTraker, "sbcdefs")
myDataAdapter.Update(dsTraker, "scustomers")
myDataAdapter.Update(dsTraker, "sinbndlst")
myDataAdapter.Update(dsTraker, "sinbound")
myDataAdapter.Update(dsTraker, "sinventry")
myDataAdapter.Update(dsTraker, "slineitem")
myDataAdapter.Update(dsTraker, "slookups")
myDataAdapter.Update(dsTraker, "snextone")
myDataAdapter.Update(dsTraker, "sproducts")
myDataAdapter.Update(dsTraker, "sshipping")
myDataAdapter.Update(dsTraker, "ssystrakr")
myDataAdapter.Update(dsTraker, "suserdefs")
Catch ex As Exception
End Try
cn.Close()


.



Relevant Pages

  • Re: xml 2 sql
    ... > Ok here is what I am trying to accomplish I have 12 xml files that I want ... > load into a sqlce database. ... > Dim aXMLFiles As Array ... > Dim SqlCeEngine As SqlCeEngine ...
    (microsoft.public.pocketpc)
  • Re: Loading mulitple files
    ... Afterwards I pull all the xml files to a ... dim logXML, logPath, logfile, logtext, arrLogs, arrText ... set att = logXML.createAttribute ... Set oApps = oXMLDoc.DocumentElement.SelectNodes ...
    (microsoft.public.scripting.vbscript)
  • Re: Loading mulitple files
    ... Afterwards I pull all the xml files to a ... dim logXML, logPath, logfile, logtext, arrLogs, arrText ... : set att = logXML.createAttribute ...
    (microsoft.public.scripting.vbscript)
  • ASP.Net app cannot read XML with Anonymous Authentication disabled
    ... real simple XML files from it's local directory. ... Dim ProjReader As XmlReader = Nothing ... 'Get XML Data for Projector and load in Projector Dropdown ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: Importing XML into SQL using DTS
    ... >I need to import large XML files into an SQL table. ... > Dim objXMLDOM ... > Dim objADORS ...
    (microsoft.public.sqlserver.xml)