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
相关文档:
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 ......
using System;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
namespace ImageDB
{
public partial class FormImageAccess : Form
{
#region 自定义对象 ......
<!--#include file="config.asp" -->
<!--#include file="Fun.asp" -->
<%
'数据库管理类
class Datas
'备份
public sub Bk()
Set fso=server.createobject("scripting.filesystemobject")
fso.CopyFile Server.MapPath(SiteDataPath),Server.MapPath(SiteDataBakPath)
......
最近做个项目需要连接到一个第3方软件用到的MDB数据库,该MDB文件是用户级加密,虽然合作方给了用户名,说没有密码,但是却无法用ADO进行查询,报没有权限。用ACCESS打开也是一样,无法看到表里的数据。于是到网上去搜,结果只搜到如何用ACCESS对MDB进行加密和打开加密文件,这个跟编程无关,就没细看。关于ADO连接加 ......
每个函数都可以将表达式 (表达式:算术或逻辑运算符、常数、函数和字段名称、控件和属性的任意组合,计算结果为单个值。表达式可执行计算、操作字符或测试数据。)强制转换为特定的数据类型 (数据类型:决定字段可拥有的数据类型的字段特征。数据类型包括 Boolean、Integer、Long、Currency、Single、Double、Date、Strin ......