Access数据库转换为sdf数据库及SqlCeHelper类
在做Mobile项目时遇到一个问题,我们的Mobile项目需要使用SqlCe数据库,而客户提供的带有原始数据的数据库是Access格式的,所以我们面临的第一个问题是将Access数据库(*.mdb)转换成SqlCe数据库(*.sdf)。网上搜索的很多资料是关于如何将SqlServer 2005与SqlCe数据进行同步,主要是通过发布订阅及RDA编程来实现,可以参考的资料有:
用 SQL Server Management Studio 管理 SQL Server Compact Edition 数据库
SQL CE 和 SQL Server 的同步
Step by Step: Program Microsoft SQL Server CE 2.0 Merge Replication Using .NET Compact Framework
后来找到一个工具Data Port Wizard可以直接将其他数据库转换为SqlCe数据库,省了不少事。只是转换过程中遇到一个小小的问题,在客户提供的Access数据库的关系里设置了很多表与表之间的关系,但所有的表都没有设置主键,所以转换时就抛出异常。为了省事,我将Access表的关系全部删除,这样就顺利的将Access数据库转换成SqlCe 3.5版本的sdf数据库了。
至于操作SqlCe的数据层的类,在网上找到一个SqlCeHelper.cs,转贴如下:
using System;
using System.Data;
using System.Data.SqlServerCe;
using System.Configuration;
using System.Collections;
namespace SbuxMobile.DAL
{
///
/// The SqlCeHelper class is intended to encapsulate high performance, scalable best practices for
/// common uses of SqlClient
///
public sealed partial class SqlCeHelper
{
#region private utility methods & constructors
// Since this class provides only static methods, make the default constructor private to prevent
// instances from being created with "new SqlCeHelper()"
private SqlCeHelper() { }
///
/// This method is used to attach array of SqlCeParameters to a SqlCeCommand.
///
/// This method will assign a value of DbNull to any parameter with a direction of
/// InputOutput and a value of null.
///
/// This behavior will prevent default values from being used, but
/// this will be the less common case than an intended pure output pa
相关文档:
创建基于对话框的应用程序ADO,向对话框中添加一个列表视图控件,并为其添加变量m_Grid
第一步:ADO对象的导入
在StdAfx.h头文件中:
// stdafx.h : include file for standard system include files,
// or project specific include files that are used frequently, bu
// are ......
接上面的一篇。
方法2:
创建一个单文档应用程序 -> 下一步 -> 选择 Database view without file support ,
单击 Data Source 在弹出的 "数据连接属性" 对话框中,选择 " Microsoft Jet 4.0 OLE DB Provider " 。
单击 下一步 在"选择或输入数据库名称 中,选择 数据库文件所在的路径。同第一篇所述方法,使用默 ......
接 2
方法3 :
这种方法也需要用户自己创建一个数据源,但是,所需要进行的步骤,比方法2要少上许多。
创建好用户表。
创建数据源(控制面板->数据管理->数据源 双击 -> 选择 文件 DSN -> 添加 -> Microsoft Access Driver -> 手动输入DSN 保存的位置及名称 -> 选择(S) 并选 ......
1.Asc
说明:返回字母的Acsii值
举例:select Asc("A")返回65
2.Chr
说明:将ascii值转换到字符
举例:select chr(65)返回"A"
3.Format
说明:格式化字符串
举例:Select Format(now(),"yyyy-mm-dd")返回类似于"2008-04-03"
&n ......
access时间函数的使用
DateDiff('yyyy',[出生日期],Date())>30 此条件日期/时间字段,如“出生日期”,只有某人的出生日期和今天的日期相差的年数大于30的记录才能包含着查询记录中。
如:SELECT *
&n ......