xml 2 sql
- From: "Chuck Hecht" <checht@xxxxxxxxxxxxxxxxx>
- Date: Thu, 12 Jan 2006 07:05:03 -0800
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()
.
- Prev by Date: Re: Memory leak with container controls
- Next by Date: Wifi connection programmatically without WZC
- Previous by thread: Keep LCD Screen On
- Next by thread: Wifi connection programmatically without WZC
- Index(es):
Relevant Pages
|