simple but urgent request
i have db with 3 tables
1. emp_master (emp_id, emp_name, emp_pasword)
2. task_master (task_id, task_name, task_starttime, task_completiontime, task_endtime)
3. task_status (emp_id, task_id, task_date,task_statusflag)
first i need a dataset for the above filled with data, next i want to generate an xml file for the above database, then i will send that xml file to mobile pc..
in mobile pc application, i need to generate dataset from that xml... and i will need to update the dataset... which will inturn update the xml file...
back in my pc i will use that xml file to update my database....
please give me code for this... i am unable to write by myself... because i am new to xml and dataset...
i need it urgent... help!!!!!
Re: simple but urgent request
I'm new to it, too. Here is a function I use for dumping some tables into an XML string:
VB Code:
'This creates the XML string to be exported. Only new data goes if typ is 1. Otherwise
'ALL of the data goes.
Private Function MakeOutput(ByVal typ As Integer) As String
Dim lDadapt As System.Data.SqlServerCe.SqlCeDataAdapter
Dim lDset As New System.Data.DataSet
Dim st1 As String
Dim cmd As System.Data.SqlServerCe.SqlCeCommand
Try
cmd = dbM.GetCommand
Catch ex As Exception
MsgBox("Database is not valid.")
MakeOutput = ""
Exit Function
End Try
Try
If typ = 1 Then
cmd.CommandText = "SELECT * FROM EffortTable WHERE Downloaded < 2"
'Get the tables and put them in the dataset.
lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
lDadapt.Fill(lDset, "EffortTable")
lDadapt.Dispose()
cmd.CommandText = "SELECT * FROM FishTable WHERE Downloaded < 2 "
lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
lDadapt.Fill(lDset, "FishTable")
lDadapt.Dispose()
cmd.CommandText = "SELECT * FROM MaxAnglerNumber WHERE Downloaded < 2 "
lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
lDadapt.Fill(lDset, "MaxAnglerNumber")
'This may not be the best way to do this, but get a string of the XML.
st1 = lDset.GetXml()
Else
cmd.CommandText = "SELECT * FROM EffortTable"
'Get the tables and put them in the dataset.
lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
lDadapt.Fill(lDset, "EffortTable")
lDadapt.Dispose()
cmd.CommandText = "SELECT * FROM FishTable"
lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
lDadapt.Fill(lDset, "FishTable")
lDadapt.Dispose()
cmd.CommandText = "SELECT * FROM MaxAnglerNumber"
lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
lDadapt.Fill(lDset, "MaxAnglerNumber")
'This may not be the best way to do this, but get a string of the XML.
st1 = lDset.GetXml()
End If
MakeOutput = st1
Catch ex As System.Data.SqlServerCe.SqlCeException
MakeOutput = ""
End Try
End Function
And a function for reading in new data from the XML
VB Code:
Private Function GetTables(ByVal stXML As String) As Boolean
Dim retVal As Integer
Dim dSet As New System.Data.DataSet
Dim sRead As System.IO.StringReader
Dim xmlTxtR As System.Xml.XmlTextReader
Dim cmd As System.Data.SqlServerCe.SqlCeCommand
Dim dTable As System.Data.DataTable
Dim rw As System.Data.DataRow
'This should take what was passed in and turn it into a string.
sRead = New System.IO.StringReader(stXML)
xmlTxtR = New System.Xml.XmlTextReader(sRead)
dSet.ReadXml(xmlTxtR, XmlReadMode.InferSchema)
'Now we need to kill off anything that is in the shift or location table, because if
'there is anything in there that is not in the incoming thing, you are basically ****ed.
'However, this could also mean that you should clear the data from the database, but that
'is probably NOT a very good idea, because actual data is lost. Residual data associated
'with table entries that no longer exist are a problem on the downstream side, not the
'upstream side.
Try
cmd = dbM.GetCommand
cmd.CommandText = ("DELETE FROM ShiftTable")
cmd.ExecuteNonQuery()
cmd.CommandText = ("DELETE FROM LocationTable")
cmd.ExecuteNonQuery()
Catch ex As System.Data.SqlServerCe.SqlCeException
MsgBox(ex.Message)
End Try
'Now the data from the dataset must be shifted to the table.
dTable = dSet.Tables("ShiftTable")
For Each rw In dTable.Rows
cmd.CommandText = ("INSERT INTO ShiftTable (ShiftName) VALUES(?)")
cmd.Parameters.Add("ShiftName", rw.Item("ShiftName"))
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
Next
dTable = dSet.Tables("LocationTable")
For Each rw In dTable.Rows
cmd.CommandText = ("INSERT INTO LocationTable (LocationName) VALUES(?)")
cmd.Parameters.Add("LocationName", rw.Item("LocationName"))
cmd.ExecuteNonQuery()
cmd.Parameters.Clear()
Next
cmd.Dispose()
sRead.Close()
xmlTxtR.Close()
GetTables = True
End Function
You should be able to modify this fairly simply to whatever you are trying to do. I have no idea whether this is an optimal solution or not, but it is a workable one.