MS SQL Server
  Home arrow MS SQL Server arrow Page 2 - 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 in Pocket PC programmatically: source code


    (Page 2 of 4 )

    Make sure that you have completed all the steps in the previous section before proceeding further.  Go through the following steps to write the code.

    • Double click on the “Create Table” button to go to the code window.
    • Include the following two lines at the top:
    Imports System.Data.Common
    Imports System.Data.SqlServerCe
    • Just before the “btnCreateTable_click” event, declare a variable to hold the connection string (as follows):
        Dim connStr As String = "Data Source = emp.sdf; Password = jagchat"
    • You can modify the connection string according to your requirements.  Within the button click event, copy the code in such a way that it looks like this:
    Imports System.Data.Common
    Imports System.Data.SqlServerCe
    Public Class Form1
        Inherits System.Windows.Forms.Form
          .
          .
          .
          .
        Dim connStr As String = "Data Source = emp.sdf; Password = jagchat"
     
        Private Sub btnCreateTable_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreateTable.Click
            Try
                'creating database
                Dim engine As SqlCeEngine
                engine = New SqlCeEngine(connStr)
                engine.CreateDatabase()
                engine.Dispose()
     
                'creating table
                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 &= ")"
                Dim cmd As New SqlCeCommand(sql, cn)
                cmd.Connection.Open()
                cmd.ExecuteNonQuery()
                cmd.Connection.Close()
                cmd.Dispose()
                cn.Dispose()
     
                MessageBox.Show("Succesfully created")
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
    End Class

    In the next section, we shall see how to execute the above application.

    More MS SQL Server Articles
    More By Jagadish Chaterjee


       · 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 4 hosted by Hostway
    Stay green...Green IT