-----------------C#问题非高手务进-------------------
编程小妞儿 2010-01-28 10:07:34 下面是原是C#+SqlServer
我想把数据库换成 C#+Access 但Access没有SqlTypes这个方法,怎么把中间注释的部分换成跟Access数据库相关的方法
有好的回答再加分
引用原文:http://blog.csdn.net/CodingMouse/archive/2008/12/14/3515969.aspx
using (OleDbConnection conn = new OleDbConnection(connectionString))
{
OleDbCommand cmd = new OleDbCommand(sqltxt, conn);
conn.Open();
//MessageBox.Show(" // 执行 SQL 命令");
using (OleDbDataReader myReader = cmd.ExecuteReader(
CommandBehavior.CloseConnection |
CommandBehavior.SingleResult |
CommandBehavior.SingleRow))
{
if (myReader.Read())
{
//将数据集转换成实体集合
tmpOperator.Id = Convert.ToInt32(myReader["Id"]);
tmpOperator.ModelName = Convert.ToString(myReader["OperatorName"]);
tmpOperator.Password = Convert.ToString(myReader["Password"]);
tmpOperator.State = Convert.ToBoolean(myReader["State"]);
// 读取权限集合
//System.Data.SqlTypes.SqlBytes bytes = myReader.GetSqlBytes(3); // 只能指定列序号
// 将流反序列化为权限集合对象
//BinaryFormatter bf = new BinaryFormatter();
//if (!bytes.Equals(""))
//{
//tmpOperator.RightsCollection = (bf.Deserialize(bytes.Stream) as Dictionary<string, Model.Rights>);
//}
//else
// throw new Exception(string.Format("操作员 [{0}] 没有任何权限,禁止登录!", tmpOperator.ModelName));
}
else
//如果没有读取到内容则抛出异常
throw new Exception("登录名称或用户密码不正确!");
}