Click here to Skip to main content
11,645,889 members (77,928 online)
Click here to Skip to main content

Smart Device Login Application Using the SQL Server CE Database

, 9 Jun 2009 CPOL 90.8K 2.5K 31
Rate this:
Please Sign up or sign in to vote.
A comprehensive guide to development of .NET 2.0 Smart Clients with SQL Server CE Database

Introduction

Smart devices should be connected to the database in order improve performance and facilities. Users generally find it a bit challenging when they want to implement smart device application with database support. Using this article, I want to provide a sample demo to get in touch with smart device application with database support using Microsoft Visual Studio 2008 and MSSQL Server CE database. This article has source code in C# .NET. I used a simple data base connection and created a login page so that user can easily understand the smart device application and database connection.

Using the Code

Open Microsoft Visual Studio 2008 and Select File -> New Project -> Smart device application under Visual C# project types (as shown in Figure 1):

Figure 1: New Project Smart Device Application.

After creating a smart device application project, immediately a second popup window will appear and gives the user an option to select “Target Platform” and “.NET Compact version”.

Target Platforms types are:

  1. Pocket PC 2003
  2. Windows CE
  3. Windows Mobile 5.0 Pocket PC SDK
  4. Windows Mobile 5.0 Smart Phone SDK
  5. Windows Mobile 6 Professional SDK

If you want to use a different emulator from the above, then use the download link of pop up window.

.NET Compact Framework types are:

  1. .NET Compact Framework version 2.0
  2. .NET Compact Framework version 3.5

I am going with Device Application as shown in figure 2 below:

Figure 2: Select Project Type Application.

Now, smart device projects itself and gives you a default Mobile Form named Form1.cs.
If you want to create more than one form in a project, then Right click on Project and
Add --> New Item --> choose Windows Form and give an appropriate name. Click on OK.

If you want to change the Mobile Form that has to run first, then you have to use program.cs file inside the project.

//Note: Create a form object instance here to run first.
static void Main()
{
    Application.Run(new Form1());
} 

Now, you have to make a proper User Interface in the project. If you want to make a simple application, then make login form using .NET smart device project. First put two labels, two text boxes and two buttons on the form. Then, give them appropriate names via setting the ID in Property windows.

I have set these IDs for controls txtuname, txtpasssword, lbluname, lblpassword, btnsubmit and btnreset.

Note: In the login form, care should be taken about the password textbox, it should not display any character. Fill with * or any symbol into password char field of textbox.

Figure 3: Smart Device Form in Design Mode.

The last step for setting up the project is to add SqlServerCE database file into the current project. Right click on project --> Add --> New Item --> Database File. Give an appropriate name to this database file and then click OK. It adds appropriate database file into the project, you need to set Data Source Configuration wizard. At the first time of creation, we don't have any tables and dataset, so click on finish to create an empty dataset.

Figure 4: Add New Item Database File.

Figure 5: Data Source Configuration Wizard.

Now, go to Server Explorer window, explore your database and create a new table. This can be done using right click on table folder and selecting “Create table” option. This opens a new “Table Creation Wizard” which prompts you to enter an appropriate table name, column names, types and size.

Figure 6: Create New Table.

Figure 7: Choose Data Connection.

My table Structure is as follows:

Table Name: user
uname      nvarchar(100)
password   nvarchar(100)  

Reset Function

  /* Reset Button Code */
        private void btnreset_Click(object sender, EventArgs e)
        {
            txtuname.Text = "";
            txtpassword.Text = "";
        }

Login Function

How to connect your mobile application with database

First double click on the dataset in the Solution Explorer that we have already created. Now, add one table adapter in that dataset using the right click --> Add --> Table Adapter.
It automatically takes existing dataset as a connection for table adapter. Click on Next and Select Command Type as Use SQL Statements and click on Next. Use query builder option and select table user to select all its rows and click on Next. Select all methods to use via table adapter and click on Next. It generates a message saying that your data table and table adapter is configured successfully.

It displays data table adapter as shown in the following figure:

Figure 8: View of Table

Add this data table adapter into your form when you are using this. In our case, we have added userdatatableadpter1 into Form1.cs design mode. You cannot see this table adapter control in your toolbox until you build the smart device project. The first step is to build your project, after which you can see a frame created in your toolbox. Drag this new toolbox control in your project.

Go to the form code window and add “using System.Data.SqlServerCe;” namespace in your project.

And add the below mentioned code into your code window:

//Login button click
private void btnlogin_Click(object sender, EventArgs e)
{
    AppDatabase1DataSet ds = new AppDatabase1DataSet();
    AppDatabase1DataSet.userDataTable dt = new
          AppDatabase1DataSet.userDataTable();
    this.userTableAdapter1.Fill(dt);
    foreach (DataRow dr in dt.Rows)
    {
        if (dr[0].ToString() == txtuname.Text && dr[1].ToString() == txtpassword.Text)
        {
            txtpassword.Text = "";
            txtpassword.Text = dr[0].ToString();
            MessageBox.Show("Login Valid!");
        }
    }
} 
How to Run?
  1. Click on F5 or click on start debugging.
  2. After building project, Visual Studio pops up one selection window for user to choose target device options.
  3. Select the device and click on ok. It takes some time to load your application into device emulator.
  4. Enter the username and password and click on login. If you want to clear username and password textboxes, then click on Reset button code.

Figure 9: USA Windows Mobile 5.0 Pocket PC R2 Emulator.

Points of Interest

While implementing smart device applications using Visual Studio 2008 with the backend SQL Server CE database, I learnt by successfully handling lot of issues with SQL Server Database and smart device application. Finally, I came to the conclusion that SQL server compact edition is a reliable SQL Server database to connect with the smart device application. Most of the users are trying to connect smart device application to the existing Microsoft SQL Server database which is not possible. The limitation of Smart Device applications is that it is not possible to connect high concurrent database with Microsoft SQL Server 2005.

Thank you for reading this article. I would really appreciate your feedback.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

saurabhmsoni
Software Developer Graduate Student
United States United States
My LinkedIN Profile: http://www.linkedin.com/in/saurabhmsoni

Web Master at SJSU- College of Business

Developed new website for College of Business, SJSU using Web Content Management System 7.0, JavaScript, HTML, WordPress and Google Application Tool Urchin. http://www.sjsu.edu/lucasschool/

Maintain College of Business present site and Faculty Staff Directory pages in updating necessary academic information using ASP, HTML, CSS, WordPress, and RSS. http://www.sjsu.edu/cob

Software Developer, Gateway Technolabs PVT, Limited, India

Developed and implemented Web Based Admin System (ASP.net (C#), web service, XML, SQL Server 2005 and Crystal Report) for Gateway Technolabs private limited company offshore project of Preemploy.com (USA's Company which is recognized as a national leader in pre-employment screening).

Implemented and tested functionality of advertisement campaigns, revenue generation, crystal reporting, broadcast factor, user management and role management (using C#.net, web service, SQL Server 2005, VSS 2005, Infragistic) in Desktop based CAB – MEDIA project for Gateway Technolabs private limited company.

Software Development Intern, Bharat Sanchar Nigam Limited, India

Developed Fraud Management, intranet site (using ASP, Oracle 8.0 and Visual Basic 6.0) for CMTS Department, BSNL, National Telecommunication Company, India.

You may also be interested in...

Comments and Discussions

 
Questionwindows mobbile application Pin
Member 115893217-May-15 0:08
memberMember 115893217-May-15 0:08 
Questionwindows mobile smart device application Pin
Member 93559715-Feb-13 19:41
memberMember 93559715-Feb-13 19:41 
QuestionSmart Device Login Application Using the SQL Server CE Database Pin
edi zhu14-Oct-12 15:21
memberedi zhu14-Oct-12 15:21 
QuestionHow to run on mobile Pin
theccdds30-May-12 23:57
membertheccdds30-May-12 23:57 
QuestionSmart Device Application....................... Pin
KanakarajV31-Dec-11 2:00
memberKanakarajV31-Dec-11 2:00 
QuestionThanks , A good article , I needed it Pin
samia ghareib20-Nov-11 1:40
membersamia ghareib20-Nov-11 1:40 
GeneralMy vote of 1 Pin
shankar2008022814-Mar-11 19:59
membershankar2008022814-Mar-11 19:59 
Questioni want to take this application further Pin
naijateddy7-Nov-10 4:21
membernaijateddy7-Nov-10 4:21 
Generalsahar Pin
malakblueangel2-Aug-10 15:18
membermalakblueangel2-Aug-10 15:18 
Generalreally awesome artical god protect u :) Pin
ai_elhakim7-Jun-10 16:59
memberai_elhakim7-Jun-10 16:59 
GeneralRe: really awesome artical god protect u :) [modified] Pin
ai_elhakim7-Jun-10 18:32
memberai_elhakim7-Jun-10 18:32 
Generalplease help....:) Pin
grouchoo21-Apr-10 15:48
membergrouchoo21-Apr-10 15:48 
GeneralRe: please help....:) Pin
saurabhmsoni21-Apr-10 16:18
membersaurabhmsoni21-Apr-10 16:18 
GeneralExcellent work...just what i wanted Pin
grouchoo21-Apr-10 15:46
membergrouchoo21-Apr-10 15:46 
GeneralMy vote of 2 Pin
shaveen9-Apr-10 19:21
membershaveen9-Apr-10 19:21 
GeneralRe: My vote of 2 Pin
saurabhmsoni21-Apr-10 16:19
membersaurabhmsoni21-Apr-10 16:19 
GeneralNot seeing the user table adapter frame in the toolbox Pin
anuhoho12-Mar-10 23:21
memberanuhoho12-Mar-10 23:21 
GeneralRe: Not seeing the user table adapter frame in the toolbox Pin
anuhoho13-Mar-10 18:21
memberanuhoho13-Mar-10 18:21 
QuestionHow to connect Remote Database!! Pin
Virani19-Jan-10 23:16
memberVirani19-Jan-10 23:16 
AnswerRe: How to connect Remote Database!! Pin
saurabhmsoni30-Jan-10 18:26
membersaurabhmsoni30-Jan-10 18:26 
Questionhow to insert and delete data Pin
sdastlan17-Dec-09 8:11
membersdastlan17-Dec-09 8:11 
AnswerRe: how to insert and delete data Pin
saurabhmsoni30-Jan-10 18:19
membersaurabhmsoni30-Jan-10 18:19 
GeneralYes, you can connect directly to an SQL Server database [modified] Pin
EFEaglehouse7-Dec-09 17:00
memberEFEaglehouse7-Dec-09 17:00 
GeneralRe: Yes, you can connect directly to an SQL Server database Pin
saurabhmsoni9-Dec-09 19:09
membersaurabhmsoni9-Dec-09 19:09 
GeneralRe: Yes, you can connect directly to an SQL Server database Pin
EFEaglehouse10-Dec-09 7:29
memberEFEaglehouse10-Dec-09 7:29 
GeneralThank you very much Pin
Don Fizachi10-Sep-09 21:05
memberDon Fizachi10-Sep-09 21:05 
Many thanks for this article. It made life a little bit easier Smile | :)
GeneralRe: Thank you very much Pin
saurabhmsoni16-Sep-09 9:57
membersaurabhmsoni16-Sep-09 9:57 
GeneralGood work Pin
Md. Marufuzzaman25-Aug-09 7:43
groupMd. Marufuzzaman25-Aug-09 7:43 
GeneralRe: Good work Pin
saurabhmsoni25-Aug-09 18:40
membersaurabhmsoni25-Aug-09 18:40 
GeneralThanks For the great article. Pin
MDeepa23-Aug-09 22:44
memberMDeepa23-Aug-09 22:44 
GeneralRe: Thanks For the great article. Pin
saurabhmsoni25-Aug-09 18:40
membersaurabhmsoni25-Aug-09 18:40 
GeneralReally heplful article Pin
mahek shah8-Aug-09 8:10
membermahek shah8-Aug-09 8:10 
GeneralRe: Really heplful article Pin
saurabhmsoni12-Aug-09 18:19
membersaurabhmsoni12-Aug-09 18:19 
Generalnice article for beginner Pin
nikunjmochi8-Jul-09 18:28
membernikunjmochi8-Jul-09 18:28 
GeneralRe: nice article for beginner Pin
saurabhmsoni9-Jul-09 12:54
membersaurabhmsoni9-Jul-09 12:54 
Generalreally good article Pin
Aditi Jogi7-Jul-09 19:20
memberAditi Jogi7-Jul-09 19:20 
GeneralRe: really good article Pin
saurabhmsoni9-Jul-09 12:53
membersaurabhmsoni9-Jul-09 12:53 
GeneralIts a great tutorial, thanks Pin
androsja18-Jun-09 17:17
memberandrosja18-Jun-09 17:17 
GeneralRe: Its a great tutorial, thanks Pin
saurabhmsoni19-Jun-09 8:13
membersaurabhmsoni19-Jun-09 8:13 
GeneralError : Failed to retrive data for this request Pin
RagsEshu14-Jun-09 19:20
memberRagsEshu14-Jun-09 19:20 
GeneralRe: Error : Failed to retrive data for this request Pin
codesoftconsult15-Jun-09 12:15
membercodesoftconsult15-Jun-09 12:15 
GeneralJust what I was looking for! Pin
thomasdrago14-Jun-09 10:16
memberthomasdrago14-Jun-09 10:16 
GeneralRe: Just what I was looking for! Pin
codesoftconsult15-Jun-09 12:16
membercodesoftconsult15-Jun-09 12:16 
Generalmy vote of 1 Pin
Tammam Koujan9-Jun-09 7:26
memberTammam Koujan9-Jun-09 7:26 
GeneralRe: my vote of 1 Pin
saurabhmsoni9-Jun-09 8:24
membersaurabhmsoni9-Jun-09 8:24 
GeneralMy vote of 1 Pin
Tammam Koujan9-Jun-09 7:24
memberTammam Koujan9-Jun-09 7:24 
GeneralRe: My vote of 1 Pin
saurabhmsoni9-Jun-09 7:57
membersaurabhmsoni9-Jun-09 7:57 
GeneralGreat article thanks Pin
bijulsoni8-Jun-09 15:25
memberbijulsoni8-Jun-09 15:25 
GeneralRe: Great article thanks Pin
saurabhmsoni8-Jun-09 18:24
membersaurabhmsoni8-Jun-09 18:24 
GeneralNice Pin
Savara8-Jun-09 11:00
memberSavara8-Jun-09 11:00 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.150731.1 | Last Updated 9 Jun 2009
Article Copyright 2009 by saurabhmsoni
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid