Results 1 to 2 of 2

Thread: simple but urgent request

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2005
    Posts
    62

    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!!!!!

  2. #2
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106

    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:
    1. 'This creates the XML string to be exported. Only new data goes if typ is 1. Otherwise
    2.     'ALL of the data goes.
    3.     Private Function MakeOutput(ByVal typ As Integer) As String
    4.         Dim lDadapt As System.Data.SqlServerCe.SqlCeDataAdapter
    5.         Dim lDset As New System.Data.DataSet
    6.         Dim st1 As String
    7.         Dim cmd As System.Data.SqlServerCe.SqlCeCommand
    8.  
    9.         Try
    10.             cmd = dbM.GetCommand
    11.         Catch ex As Exception
    12.             MsgBox("Database is not valid.")
    13.             MakeOutput = ""
    14.             Exit Function
    15.         End Try
    16.  
    17.         Try
    18.             If typ = 1 Then
    19.                 cmd.CommandText = "SELECT * FROM EffortTable WHERE Downloaded < 2"
    20.                 'Get the tables and put them in the dataset.
    21.                 lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    22.                 lDadapt.Fill(lDset, "EffortTable")
    23.                 lDadapt.Dispose()
    24.                 cmd.CommandText = "SELECT * FROM FishTable WHERE Downloaded < 2 "
    25.                 lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    26.                 lDadapt.Fill(lDset, "FishTable")
    27.                 lDadapt.Dispose()
    28.                 cmd.CommandText = "SELECT * FROM MaxAnglerNumber WHERE Downloaded < 2 "
    29.                 lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    30.                 lDadapt.Fill(lDset, "MaxAnglerNumber")
    31.  
    32.                 'This may not be the best way to do this, but get a string of the XML.
    33.                 st1 = lDset.GetXml()
    34.             Else
    35.                 cmd.CommandText = "SELECT * FROM EffortTable"
    36.                 'Get the tables and put them in the dataset.
    37.                 lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    38.                 lDadapt.Fill(lDset, "EffortTable")
    39.                 lDadapt.Dispose()
    40.                 cmd.CommandText = "SELECT * FROM FishTable"
    41.                 lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    42.                 lDadapt.Fill(lDset, "FishTable")
    43.                 lDadapt.Dispose()
    44.                 cmd.CommandText = "SELECT * FROM MaxAnglerNumber"
    45.                 lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    46.                 lDadapt.Fill(lDset, "MaxAnglerNumber")
    47.  
    48.                 'This may not be the best way to do this, but get a string of the XML.
    49.                 st1 = lDset.GetXml()
    50.             End If
    51.             MakeOutput = st1
    52.         Catch ex As System.Data.SqlServerCe.SqlCeException
    53.             MakeOutput = ""
    54.         End Try
    55.     End Function

    And a function for reading in new data from the XML
    VB Code:
    1. Private Function GetTables(ByVal stXML As String) As Boolean
    2.         Dim retVal As Integer
    3.         Dim dSet As New System.Data.DataSet
    4.         Dim sRead As System.IO.StringReader
    5.         Dim xmlTxtR As System.Xml.XmlTextReader
    6.         Dim cmd As System.Data.SqlServerCe.SqlCeCommand
    7.         Dim dTable As System.Data.DataTable
    8.         Dim rw As System.Data.DataRow
    9.  
    10.  
    11.         'This should take what was passed in and turn it into a string.
    12.         sRead = New System.IO.StringReader(stXML)
    13.  
    14.         xmlTxtR = New System.Xml.XmlTextReader(sRead)
    15.         dSet.ReadXml(xmlTxtR, XmlReadMode.InferSchema)
    16.  
    17.         'Now we need to kill off anything that is in the shift or location table, because if
    18.         'there is anything in there that is not in the incoming thing, you are basically ****ed.
    19.  
    20.         'However, this could also mean that you should clear the data from the database, but that
    21.         'is probably NOT a very good idea, because actual data is lost. Residual data associated
    22.         'with table entries that no longer exist are a problem on the downstream side, not the
    23.         'upstream side.
    24.         Try
    25.             cmd = dbM.GetCommand
    26.             cmd.CommandText = ("DELETE FROM ShiftTable")
    27.             cmd.ExecuteNonQuery()
    28.             cmd.CommandText = ("DELETE FROM LocationTable")
    29.             cmd.ExecuteNonQuery()
    30.         Catch ex As System.Data.SqlServerCe.SqlCeException
    31.             MsgBox(ex.Message)
    32.         End Try
    33.  
    34.         'Now the data from the dataset must be shifted to the table.
    35.         dTable = dSet.Tables("ShiftTable")
    36.         For Each rw In dTable.Rows
    37.             cmd.CommandText = ("INSERT INTO ShiftTable (ShiftName) VALUES(?)")
    38.             cmd.Parameters.Add("ShiftName", rw.Item("ShiftName"))
    39.             cmd.ExecuteNonQuery()
    40.             cmd.Parameters.Clear()
    41.         Next
    42.  
    43.         dTable = dSet.Tables("LocationTable")
    44.         For Each rw In dTable.Rows
    45.             cmd.CommandText = ("INSERT INTO LocationTable (LocationName) VALUES(?)")
    46.             cmd.Parameters.Add("LocationName", rw.Item("LocationName"))
    47.             cmd.ExecuteNonQuery()
    48.             cmd.Parameters.Clear()
    49.         Next
    50.  
    51.         cmd.Dispose()
    52.         sRead.Close()
    53.         xmlTxtR.Close()
    54.         GetTables = True
    55.     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.
    My usual boring signature: Nothing

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width