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();

  • 相关阅读:
    Dapper数据库字段和model属性映射
    SQLServer性能调优之缓存
    python&django 实现页面中关联查询小功能(基础篇)
    pythonのdjango select_related 和 prefetch_related()
    pythonのdjango 在控制台用log打印操作日志
    pythonのdjango Form简单应用。
    pythonのdjango 信号
    pythonのdjango 缓存
    pythonのdjango CSRF简单使用
    pythonのdjango Session体验
  • 原文地址:https://www.cnblogs.com/TNTZWC/p/1456644.html
Copyright © 2011-2022 走看看