using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlServerCe;
namespace USTC
{
public class CEDB
{
private System.Data.SqlServerCe.SqlCeConnection Conn = null;
/// <summary>
/// 创建数据库连接
/// </summary>
/// <param name="constr">例如constr="Data Source=//My Documents//db.sdf"</param>
public CEDB(string constr)
{
Conn = new System.Data.SqlServerCe.SqlCeConnection(constr);
}
public void Open()
{
if (Conn.State.ToString().Trim().Equals("Open"))
{
Conn.Close();
}
Conn.Open();
}
public void Close()
{
if (Conn.State.ToString().Trim().Equals("Open"))
{
Conn.Close();
}
}
public void ExecuteSql(string sql)
{
SqlCeCommand MyCommand = new SqlCeCommand(sql, Conn);
MyCommand.ExecuteNonQuery();
Conn.Close();
}
public SqlCeDataReader GetDataReader(string strCMD)
{
SqlCeDataReader myReader;
SqlCeCommand mycommand = new SqlCeCommand();
mycommand.CommandText = strCMD;
mycommand.Connection = Conn;
myReader = mycommand.ExecuteReader();
return myReader;
}
public DataSet getDataSet(string searchString, bool isStoredProcedure)
{
DataSet ds = new DataSet();
SqlCeDataAdapter adapter = new SqlCeDataAdapter(searchString, this.Conn);
if (isStoredProcedure)
adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
adapter.Fill(ds);
adapter.Dispose();
return ds;
}
}
}