![]() |
Platforms, Frameworks & Libraries »
Mobile Development »
Database
Beginner
License: The Code Project Open License (CPOL)
How to Save and Update the Data in Windows Mobile using Emulator and Retrieve them BackBy sun1programmerThis article shows you how you can get your saved data once you closed the Windows mobile emulator. |
VB, WinMobile (PocketPC-2002), SQL-Server (SQL-CE), Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
Many people ask me how we can insert data in SQL Server Compact Edition (CE) database. Actually they had written the code and until they close the emulator, they have those modified/inserted data, but as soon as they close the emulator the data is not reflected in the CE db. They are wondering, "How can that be possible?"
Let’s take a simple example so you can understand the basic concept of what happens behind the scenes:
As compared to the above scenario, when you run your mobile application and it's open in emulator, then both the OS and the emulator are two different machines. Your CE db of OS is totally different from your emulator CE db, so whatever you changed in your emulator db is not getting reflected in your OS.
For example, when you deploy your application in Windows mobile and when you modify the data, the modified data is displayed in mobile not in the OS where you developed that application.
One way I know to do it is by sharing the storage card of Mobile application and pasting the modified db of CE into that shared directory and reusing it.
SampleMobileApplication. SampleMobileApplication” project and press right mouse button to open property and change the Output File folder path: ID and Name. Imports System.Data
Imports System.Data.SqlServerCe
Imports System.IO
Public Class frmEmp
Private Sub btnGetEmployees_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnGetEmployees.Click
GetTableData()
End Sub
Private Sub GetTableData()
Dim conn As SqlCeConnection = Nothing
Try
btnGetEmployees.Enabled = False
conn = New SqlCeConnection("Data Source = _
\Program Files\SampleMobileApplication\mydatabase.sdf;")
conn.Open()
Dim cmd As SqlCeCommand = conn.CreateCommand()
Dim dAdp As SqlCeDataAdapter = New SqlCeDataAdapter()
Dim ds As New DataSet
cmd.CommandText = "SELECT * FROM EMP"
dAdp.SelectCommand = cmd
cmd.ExecuteReader()
dAdp.Fill(ds)
dgEmp.DataSource = ds.Tables(0)
Catch ex As Exception
Finally
conn.Close()
btnGetEmployees.Enabled = True
End Try
End Sub
Private Sub btnAddNew_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnAddNew.Click
Dim frmAddNewEmp As New frmAddEmp
frmAddNewEmp.Show()
End Sub
End Class
Imports System.Data
Imports System.Data.SqlServerCe
Imports System.IO
Public Class frmAddEmp
Private Sub btnBack_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnBack.Click
Me.Close()
End Sub
Private Sub btnSave_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles btnSave.Click
If txtID.Text.Trim.Equals(String.Empty) Then
MessageBox.Show("Please enter three digit employee ID.", Me.Text)
ElseIf txtName.Text.Trim.Equals(String.Empty) Then
MessageBox.Show("Please enter employee name.", Me.Text)
ElseIf txtID.Text.Length > 3 Then
MessageBox.Show("Invalid employee ID length, _
only 3 digits are supported.", Me.Text)
ElseIf txtName.Text.Length > 255 Then
MessageBox.Show("Invalid employee name length, _
only 255 character are supported.", Me.Text)
Else
Dim conn As SqlCeConnection = Nothing
Try
conn = New SqlCeConnection("Data Source = _
\Program Files\SampleMobileApplication\mydatabase.sdf;")
conn.Open()
Dim cmd As SqlCeCommand = conn.CreateCommand()
Dim dAdp As SqlCeDataAdapter = New SqlCeDataAdapter()
Dim ds As New DataSet
cmd.CommandText = String.Format("INSERT INTO EMP(ID, _
[NAME]) VALUES ('{0}','{1}')", txtID.Text, txtName.Text)
dAdp.InsertCommand = cmd
cmd.ExecuteNonQuery()
MessageBox.Show("Saved Successfully.", Me.Text)
txtID.Text = String.Empty
txtName.Text = String.Empty
txtID.Focus()
Catch ex As Exception
MessageBox.Show(ex.Message, Me.Text)
Finally
conn.Close()
End Try
End If
End Sub
End Class
SampleMobileApplication” and click the Get Employees button.
Emp table. | You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+PgUp/PgDown to switch pages.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 6 Jan 2009 Editor: Deeksha Shenoy |
Copyright 2009 by sun1programmer Everything else Copyright © CodeProject, 1999-2010 Web17 | Advertise on the Code Project |