In this example I am try to use SQL Compact Edition with Smart Device Applications.
We can store data and update the data in the device using SQL CE, so lets start building a example.
Create SmartDeviceProject and add 2 Forms to it, please design the Form1 & Form2 as displayed in the Screen shot.
Now lets create a SQL CE database file, for that please right click on the project add new file and select Database file and name it as Employees.sdf
After adding the database file, create a table with following fields.
ID int
Name nVarchar
City nVarchar
Designation nVarchar
Now we are ready with design part lets write some code to insert data into table.
Now double click on the Add button and add following code, in the following code we are creating SQLCeConncetion object and SQLCeCommand Object to insert the data into the .sdf file, it is almost similar how we insert data into normal SQL Server database, normally our database file will be saved on the device where the application is installed so I have taken the path of the .sdf and creating a connection.
Double click on the View button and create a object for Form2 where will show all the employees details.
Now open the Form2 and add grid and one button as shown in the screen shot above, in Form2_Load event write the code to fill the datagrid, double click on back button and write a code to go back to Form1
Now we are ready with our code let built, run and Test
Subscribe to:
Post Comments (Atom)
Hi,
ReplyDeletei have follow the procedure here to create the mobile application but i had found out a problem here. That is the data that i inserted into the pocketPC is not update to the database in visual studio. After i close the pocketPC and reopen it, the data that i have inserted before is lost. May i know what is the problem and how to keep the data?
Thank you.
jiahui
Tanx man!!!!!!!!!!!!
ReplyDelete