MS SQL Server
  Home arrow MS SQL Server arrow Page 4 - SQL Server CE Programming with Pocket PC a...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
MS SQL SERVER

SQL Server CE Programming with Pocket PC and Visual Studio.NET 2003: Databases and Tables
By: Jagadish Chaterjee
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 18
    2006-05-22

    Table of Contents:
  • SQL Server CE Programming with Pocket PC and Visual Studio.NET 2003: Databases and Tables
  • Creating SQL Server CE databases and tables in Pocket PC programmatically: source code
  • Creating SQL Server CE databases and tables on Pocket PC programmatically: deployment
  • Creating SQL Server CE databases and tables on Pocket PC programmatically: explanation

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    SQL Server CE Programming with Pocket PC and Visual Studio.NET 2003: Databases and Tables - Creating SQL Server CE databases and tables on Pocket PC programmatically: explanation


    (Page 4 of 4 )

    In this section, I shall explain to you the source code I presented in the previous sections.  I shall explain it part by part.  Let us start with the following:

    Imports System.Data.Common
    Imports System.Data.SqlServerCe

    To work with Microsoft SQL Server CE in .NET, we need to add a reference and import the above two namespaces (or assemblies).  It is quite different from the standard SQL Server 7.0/2000/2005 editions.  The namespace “System.Data.SQLClient” would never be used to work with SQL Server CE databases. 

    Further proceeding, we have the following:

    Dim connStr As String = "Data Source = emp.sdf; Password = jagchat"

    The above statement specifies the connection string for the database.  It would be a bit different from the traditional connection string we use with a traditional SQL Server database. Unlike the traditional SQL Server connection string, we need to provide the path of the database file.  Further proceeding we have the following:

                'creating database
                Dim engine As SqlCeEngine
                engine = New SqlCeEngine(connStr)
                engine.CreateDatabase()
                engine.Dispose()

    The above code fragment simply creates an object based on the class “SqlCeEngine” available in the “System.Data.SqlServerCe” namespace.  We provided a connection string as the parameter while creating the object.  The database gets created simply by calling the method “CreateDatabase” related to the “SqlCeEngine” class. 

    Further proceeding we have the following:

                Dim cn As New SqlCeConnection(connStr)
                Dim sql As String
                sql = "CREATE TABLE emp "
                sql &= "("
                sql &= "    empno   int     PRIMARY KEY,"
                sql &= "    ename   nvarchar(20),"
                sql &= "    sal     float,"
                sql &= "    deptno  int"
                sql &= ")"

    To work with SQL Server CE, we need to open a database connection to an existing database.  For the traditional SQL Server, we will generally use “SQLConnection.”  In this scenario, we use “SqlCeConnection” which is specifically dedicated for SQL Server CE databases. The above code fragment also frames a “CREATE TABLE” statement to create our own table.

    Further proceeding, we have the following:

    Dim cmd As New SqlCeCommand(sql, cn)
                cmd.Connection.Open()
                cmd.ExecuteNonQuery()
                cmd.Connection.Close()
                cmd.Dispose()
                cn.Dispose()

    To work with any SQL command with a traditional SQL Server, we will work with the “SQLCommand” object.  In this scenario, we use “SqlCeCommand” which is specifically dedicated for SQL Server CE databases.  The above code fragment simply creates a “command” object (accepting our framed SQL statement and database connection as parameters) and executes it.  Before executing the command, we need to open the connection to the database (which is achieved in the second statement in the code fragment above).

    That completes our understanding of creating databases and tables using Pocket PC for SQL Server CE.

    I developed the application using Microsoft Windows Server 2003 Standard Edition with Microsoft Visual Studio.NET 2003 Enterprise Architect and Pocket PC SDK 2003 (along with additional emulators downloaded).   

    In my upcoming articles, I shall concentrate further on developing advanced Pocket PC applications.  So, keep close tabs on this website :)

    Any comments, suggestions, feedback, bugs, errors, enhancements are highly appreciated at jag_chat@yahoo.com


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hello guys! another article on programming Pocket PC. Have it, enjoy and give me...
     

    MS SQL SERVER ARTICLES

    - Completing the Introduction to Transact-SQL
    - A Brief Introduction to Transact-SQL
    - Lookups and Blocking Bad Data
    - Field Validation Rules for Blocking Bad Data
    - Using Masks to Block Bad Data
    - Blocking Bad Data
    - Using @@ROWCOUNT and TABLE Variables for Dat...
    - How to Use Variables, IF and CASE in Databas...
    - Creating Important Aspects of Notification S...
    - Working wth Variables in Database Interactio...
    - Delving Deeper into Notification Services
    - Notification Services
    - Building a Multi-table Report with SQL 2005 ...
    - A Secure Way of Building Connection Strings
    - Transferring a Database Using the SSIS Desig...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
    Stay green...Green IT