Results 1 to 8 of 8

Thread: [RESOLVED] Windows CE 5.0 CDB and MDB files

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Resolved [RESOLVED] Windows CE 5.0 CDB and MDB files

    I am looking for more info or an example of how to insert or delete data into CDB (converted from MDB) files using ADOCE connection.

    Is this possible?

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

    Re: Windows CE 5.0 CDB and MDB files

    What version of language are you using? With .NET, the DB is SQLServerCE, and dealing with that is fairly straightforward, as there is a whole namespace with a suite of tools for working with such a database. I don't believe you can use the classes in that namespace to work with other types of databases, and I don't think that ODBC or OLEDB namespaces are available for the .NET Compact Framework.
    My usual boring signature: Nothing

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Re: Windows CE 5.0 CDB and MDB files

    Yes, I am using .NET.

    I need the ability to store data entered into a handheld, and then import it onto a PC based app that uses MS Access as a backend. Basically I need 2 tables with 8 fields each.

    We are in the process of converting the app to run Sql Server, but need to import data now.

    Is it possible to use SqlCe, then import the data to an Access db?


    hxxp://blogs.msdn.com/sqlmobile/archive/2006/06/01/612768.aspx

    I know it is a backward direction, but looking for a temp solution. Thanks.
    Last edited by easymoney; Mar 14th, 2007 at 12:39 AM.

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Re: Windows CE 5.0 CDB and MDB files

    Okay, I have been doing some reading. ActiveSync dropped support for mdb file conversions, hence my problem.

    So I have to use SqlCe on the handheld, then ActiveSync the Db to the desktop PC. Then I need to convert the Sql back to MDb format, then import using the application. I assume this process will be streamlined once desktop app is upgraded to Sql server.


    Maybe this is the fix that was claimed Microsoft promised...

    Not sure about rules regarding posting links, hope I don't get in trouble.

    Code:
    Microsoft SQL Server 2005 Compact Edition Access Database Synchronizer
    
    hxxp://www.microsoft.com/downloads/details.aspx?FamilyID=b967347a-5dd0-445c-8a9f-aea3db9ec4bc&DisplayLang=en
    A side note, ..... what is with all the differnet versions of Ce and Windows Mobile... Ce 3.0, Ce5.0, Mobile 5.0 and now Mobile 6 ????
    Last edited by easymoney; Mar 14th, 2007 at 11:24 PM.

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

    Re: Windows CE 5.0 CDB and MDB files

    I have done what you are trying to do, though I'm not entirely sure whether I have any code that would be of any value to you. The basic solution you need is to take the SQLServerCE, and dump it into XML, transmit the XML, and load it into Access. This works, and really takes VERY little code. The part that I have never absolutely solved was the transfer part. I used TCP, and had no experience with it at all. While what I had was working, it may have only worked when there were only a few records. I don't remember whether I figured out what I was doing wrong, or just abandoned the project.

    Here's an example of a function I used to create the XML string for sending:

    vb Code:
    1. Private Function MakeOutput(ByVal typ As Integer) As String
    2.         Dim lDadapt As System.Data.SqlServerCe.SqlCeDataAdapter
    3.         Dim lDset As New System.Data.DataSet
    4.         Dim st1 As String
    5.         Dim cmd As System.Data.SqlServerCe.SqlCeCommand
    6.  
    7.         Try
    8.             cmd = dbM.GetCommand
    9.         Catch ex As Exception
    10.             MsgBox("Database is not valid.")
    11.             MakeOutput = ""
    12.             Exit Function
    13.         End Try
    14.  
    15.         Try
    16.             'For either one, the ID must be included.
    17.             cmd.CommandText = "SELECT Ident FROM IDTable WHERE IDId = 1"
    18.             lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    19.             lDadapt.Fill(lDset, "Identifier")
    20.             lDadapt.Dispose()
    21.  
    22.             If typ = 1 Then
    23.                 cmd.CommandText = "SELECT * FROM EffortTable WHERE Downloaded < 2"
    24.                 'Get the tables and put them in the dataset.
    25.                 lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    26.                 lDadapt.Fill(lDset, "EffortTable")
    27.                 lDadapt.Dispose()
    28.                 cmd.CommandText = "SELECT * FROM FishTable WHERE Downloaded < 2 "
    29.                 lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    30.                 lDadapt.Fill(lDset, "FishTable")
    31.                 lDadapt.Dispose()
    32.                 cmd.CommandText = "SELECT * FROM MaxAnglerNumber WHERE Downloaded < 2 "
    33.                 lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    34.                 lDadapt.Fill(lDset, "MaxAnglerNumber")
    35.  
    36.                 If lDset.Tables("EffortTable").Rows.Count = 0 And lDset.Tables("FishTable").Rows.Count = 0 Then
    37.                     Windows.Forms.MessageBox.Show("There is no new data to be sent, so nothing will be sent.")
    38.                     st1 = ""
    39.                 Else
    40.                     'This may not be the best way to do this, but get a string of the XML.
    41.                     st1 = lDset.GetXml()
    42.                 End If
    43.             Else
    44.                     cmd.CommandText = "SELECT * FROM EffortTable"
    45.                     'Get the tables and put them in the dataset.
    46.                     lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    47.                     lDadapt.Fill(lDset, "EffortTable")
    48.                     lDadapt.Dispose()
    49.                     cmd.CommandText = "SELECT * FROM FishTable"
    50.                     lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    51.                     lDadapt.Fill(lDset, "FishTable")
    52.                     lDadapt.Dispose()
    53.                     cmd.CommandText = "SELECT * FROM MaxAnglerNumber"
    54.                     lDadapt = New System.Data.SqlServerCe.SqlCeDataAdapter(cmd)
    55.                     lDadapt.Fill(lDset, "MaxAnglerNumber")
    56.  
    57.                     'This may not be the best way to do this, but get a string of the XML.
    58.                     st1 = lDset.GetXml()
    59.                 End If
    60.                 MakeOutput = st1
    61.         Catch ex As System.Data.SqlServerCe.SqlCeException
    62.             Windows.Forms.MessageBox.Show("Error making output file." & Chr(10) & ex.Message)
    63.             MakeOutput = "FAIL"
    64.         End Try
    65.     End Function
    66.  
    67.     'This sets the downloaded bit for all of the data in the tables.
    68.     Private Sub UpdateTables()
    69.         Dim cmd As System.Data.SqlServerCe.SqlCeCommand
    70.  
    71.         Try
    72.             cmd = dbM.GetCommand
    73.         Catch ex As Exception
    74.             MsgBox("Updating Downloaded failed for unknown reason.")
    75.         End Try
    76.  
    77.         Try
    78.             cmd.CommandText = "UPDATE FishTable SET Downloaded = 2"
    79.             cmd.ExecuteNonQuery()
    80.             cmd.CommandText = "UPDATE EffortTable SET Downloaded = 2"
    81.             cmd.ExecuteNonQuery()
    82.             cmd.CommandText = "UPDATE MaxAnglerNumber SET Downloaded = 2"
    83.             cmd.ExecuteNonQuery()
    84.         Catch ex As System.Data.SqlServerCe.SqlCeException
    85.             MsgBox("Updating download failed because of: " & ex.Message)
    86.             cmd.Dispose()
    87.         End Try
    88.     End Sub
    89.  
    90.     Private Function GetTables(ByVal stXML As String) As Boolean
    91.         Dim retVal As Integer
    92.         Dim dSet As New System.Data.DataSet
    93.         Dim sRead As System.IO.StringReader
    94.         Dim xmlTxtR As System.Xml.XmlTextReader
    95.         Dim cmd As System.Data.SqlServerCe.SqlCeCommand
    96.         Dim dTable As System.Data.DataTable
    97.         Dim rw As System.Data.DataRow
    98.  
    99.  
    100.         'This should take what was passed in and turn it into a string.
    101.         sRead = New System.IO.StringReader(stXML)
    102.  
    103.         xmlTxtR = New System.Xml.XmlTextReader(sRead)
    104.         dSet.ReadXml(xmlTxtR, XmlReadMode.InferSchema)
    105.  
    106.         'Now we need to kill off anything that is in the shift or location table, because if
    107.         'there is anything in there that is not in the incoming thing, you are basically ****ed.
    108.  
    109.         'However, this could also mean that you should clear the data from the database, but that
    110.         'is probably NOT a very good idea, because actual data is lost. Residual data associated
    111.         'with table entries that no longer exist are a problem on the downstream side, not the
    112.         'upstream side.
    113.         Try
    114.             cmd = dbM.GetCommand
    115.             cmd.CommandText = ("DELETE FROM ShiftTable")
    116.             cmd.ExecuteNonQuery()
    117.             cmd.CommandText = ("DELETE FROM LocationTable")
    118.             cmd.ExecuteNonQuery()
    119.         Catch ex As System.Data.SqlServerCe.SqlCeException
    120.             MsgBox(ex.Message)
    121.         End Try
    122.  
    123.         'Now the data from the dataset must be shifted to the table.
    124.         dTable = dSet.Tables("ShiftTable")
    125.         For Each rw In dTable.Rows
    126.             cmd.CommandText = ("INSERT INTO ShiftTable (ShiftName) VALUES(?)")
    127.             cmd.Parameters.Add("ShiftName", rw.Item("ShiftName"))
    128.             cmd.ExecuteNonQuery()
    129.             cmd.Parameters.Clear()
    130.         Next
    131.  
    132.         dTable = dSet.Tables("LocationTable")
    133.         For Each rw In dTable.Rows
    134.             cmd.CommandText = ("INSERT INTO LocationTable (LocationName) VALUES(?)")
    135.             cmd.Parameters.Add("LocationName", rw.Item("LocationName"))
    136.             cmd.ExecuteNonQuery()
    137.             cmd.Parameters.Clear()
    138.         Next
    139.  
    140.         cmd.Dispose()
    141.         sRead.Close()
    142.         xmlTxtR.Close()
    143.         GetTables = True
    144.     End Function

    Oops, copied too much. Ok, it's two functions, one reads, one writes.
    My usual boring signature: Nothing

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Re: Windows CE 5.0 CDB and MDB files

    Looks pretty straight forward, I will play with this code and let you know what happens.

    Thanks.

  7. #7
    Frenzied Member
    Join Date
    Oct 2005
    Posts
    1,286

    Re: Windows CE 5.0 CDB and MDB files

    Hi,
    there is a SqlCE to Access synch tool at http://www.microsoft.com/downloads/d...displaylang=en

    Pete

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2002
    Posts
    352

    Re: Windows CE 5.0 CDB and MDB files

    Quote Originally Posted by petevick
    Hi,
    there is a SqlCE to Access synch tool at http://www.microsoft.com/downloads/d...displaylang=en

    Pete
    Yes, I finally found the promised tool as I posted this link above... but thanks for the confirmation... still a little unsure about the process.

    I guess I will mark this thread resolved as I am convinced that I need SQLServerCE and can import the data to an Access Db either via the Access Sync Tool, XML, or if all else fails CSV format....

    Now I have to learn SQLServerCE. I will make another thread detailing the process. I still have lots of questions, but this one is resolved.

    Thanks everyone

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