zoukankan      html  css  js  c++  java
  • Pocket PC 2003数据库操作

    一般CE上面的数据库程序都包括以下命名空间(包括与PC交互数据),这是从一个项目的单元文件里面拷出来的,调试环境:Windows 2003 + VS.NET 2003 + Sql Server 2000 + Sql Server CE 2.0 + Pocket PC 2003 SDK

    以下代码中很多*号,是故意处理的,你可以用你自己的变量代替


    CODE:

    using System;
    using System.IO;
    using System.Drawing;
    using System.Collections;
    using System.Windows.Forms;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlServerCe;
    using System.Runtime.InteropServices;
    using System.Threading;
    using System.Data.SqlClient;


    数据库连接代码,如下分别为连接PDA本机的SQLCE数据库和PC上的SQLSERVER数据库


    CODE:

    private string strFile = @"My Documents\****.sdf";
    private string strConn = "Data Source=" +
            @"My Documents\****.sdf";

    // Connection string.
    string SqlConn =
        "data source=Server;" +
        "initial catalog=****;" +
        "user id=sa;" +
        "pwd=sa;" +
        "workstation id=Sercer;" +
        "packet size=4096;" +
        "persist security info=False;";


    建立数据库

    CODE:

            {
                  if ( File.Exists(strFile) ) { File.Delete(strFile); }

                  SqlCeEngine dbEngine = new SqlCeEngine();
                  dbEngine.LocalConnectionString = strConn;
                  try
                  {
                      dbEngine.CreateDatabase();
                  }
                  catch( SqlCeException exSQL )
                  {
                      MessageBox.Show("Unable to create database at " +
                          strFile +
                          ". Reason: " +
                          exSQL.Errors[0].Message );
                  }
            }


    建立数据表

    CODE:

    SqlCeConnection connDB = new SqlCeConnection();
                  SqlCeCommand cmndDB = new SqlCeCommand();

                  connDB.ConnectionString = strConn;
                  connDB.Open();

                  cmndDB.Connection = connDB;
    //
                  cmndDB.CommandText =
                      " CREATE TABLE *** " +
                      " ( ID integer IDENTITY (1, 1) not null " +
                      "   CONSTRAINT PKID PRIMARY KEY" +
                      " , *** integer not null" +
    //                   "       CONSTRAINT ***" +
                      " , *** nchar(30) " +
                      " )";
                  cmndDB.ExecuteNonQuery();
    //
                  cmndDB.CommandText =
                      " CREATE TABLE UserData " +
                      " ( ** integer IDENTITY (1, 1) not null " +
                      "       CONSTRAINT PKUserID PRIMARY KEY " +
                      " , *** integer not null " +
    //                   " , CONSTRAINT *** " +
    //                   "     foreign key (***) " +
    //                   "     references Cat(***) " +
                      " , *** nchar(5) not null " +
                      " , *** nchar(5) not null " +
                      " , *** real " +
                      " , *** nchar(20) " +
                      " , *** nchar(10) " +
                      " )";
                  cmndDB.ExecuteNonQuery();

                  connDB.Close();

  • 相关阅读:
    C. New Year Book Reading
    B. New Year Permutation
    A. New Year Transportation
    D. The Child and Zoo
    python 3.6 'utf-8' codec can't decode byte 0x8b in position 1: invalid start byte错误
    VB ListView控件各种操作详解
    开发者工具下载
    phpstorm10激活加汉化
    Windows Server 2016 配置指南 之 FTP环境搭建篇
    VB.NET Jobject 解析 JSON
  • 原文地址:https://www.cnblogs.com/TNTZWC/p/1456644.html
Copyright © 2011-2022 走看看