mobile 5 中操作SDF数据库的常用方法
2007-10-28 19:34
507 查看
对于windows mobile sql 中的sdf文件,很多朋友都会用到。方法也很简单。同PC上操作SQL server,Oracle等都差不多。
下面共享一个操作SDF数据库文件的一个类,供Mobile开发新入门的朋友参考。欢迎留言进行交流。
在用此代码之前,需要 using System.Data.SqlServerCe;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class CESql
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void ConnOpen(SqlCeConnection Conn)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (Conn.State.ToString().Trim().Equals("Open"))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void ConnClose(SqlCeConnection Conn)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (Conn.State.ToString().Trim().Equals("Open"))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void ExecuteSql(string sql, SqlCeConnection Conn)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SqlCeCommand MyCommand = new SqlCeCommand(sql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
MyCommand.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public SqlCeDataReader GetDataReader(string strCMD, SqlCeConnection Conn)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SqlCeDataReader myReader;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SqlCeCommand mycommand = new SqlCeCommand();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mycommand.CommandText = strCMD;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mycommand.Connection = Conn;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
myReader = mycommand.ExecuteReader();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return myReader;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
HUST:Eric
下面共享一个操作SDF数据库文件的一个类,供Mobile开发新入门的朋友参考。欢迎留言进行交流。
在用此代码之前,需要 using System.Data.SqlServerCe;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
class CESql
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void ConnOpen(SqlCeConnection Conn)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (Conn.State.ToString().Trim().Equals("Open"))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Open();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void ConnClose(SqlCeConnection Conn)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
if (Conn.State.ToString().Trim().Equals("Open"))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public void ExecuteSql(string sql, SqlCeConnection Conn)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SqlCeCommand MyCommand = new SqlCeCommand(sql, Conn);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
MyCommand.ExecuteNonQuery();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Conn.Close();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public SqlCeDataReader GetDataReader(string strCMD, SqlCeConnection Conn)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SqlCeDataReader myReader;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
SqlCeCommand mycommand = new SqlCeCommand();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mycommand.CommandText = strCMD;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
mycommand.Connection = Conn;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
myReader = mycommand.ExecuteReader();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return myReader;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
HUST:Eric
相关文章推荐
- mobile 5 中操作SDF数据库的常用方法
- ASP常用数据库连接及操作的方法和技巧
- rails常用数据库查询操作、方法浅析
- ado.net操作数据库常用方法集锦
- ASP常用数据库连接及操作的方法和技巧
- 我自己的方法、组件、属性、变量、常量、数据库常用操作命名方法。
- 查询数据库最大的索引、静态类与非静态类的区别、后台操作DIV样式的方法、C#操作TreeView组件中的一些常用方法及具体实现
- VB使用ADODB操作数据库的常用方法
- 操作 SQL Server Mobile 2005 数据库的常用 C# 代码
- 操作 SQL Server Mobile 2005 数据库的常用 C# 代码
- ASP常用数据库连接及操作的方法和技巧
- VB使用ADO操作数据库的常用方法
- VB使用ADODB操作数据库的常用方法
- ASP常用数据库连接及操作的方法和技巧
- 操作 SQL Server Mobile 2005 数据库的常用 C# 代码 (转自黎波)
- mybatis自带常用操作数据库方法详解以及如何搭建简单的mybatis环境
- VB使用ADODB操作数据库的常用方法
- 数据库操作常用的查询方法
- VB使用ADODB操作数据库的常用方法
- PDO进行数据库操作的常用方法