基准标注不可采用的字母

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
一、升级说明 1、修复了数据库中字段值为空值的时候查询报错的Bug; 2、修复DbCommand属性ExecuteType为DbExecuteType.Scalar时执行命令报错的Bug; 3、感谢网友“尘世流浪汉”和“春之子”反馈Bug,也欢迎大家试用并提出更多建议! 二、修复功能示例 1、空值测试 public class T_Test { public int? Id { get; set; } public string Name { get; set; } } try { //创建一个数据连接 DbConnection conn = new DbConnection("Data Source=|DataDirectory|CSmsPlatThird.db;Pooling=true;FailIfMissing=false"); //设置使用的数据访问程序集 conn.AssemblyName = "System.Data.SQLite"; //设置数据工厂,这里是SQLite的数据工厂 conn.DbProviderFactory = "System.Data.SQLite.SQLiteFactory"; //创建一个数据命令 DbCommandSyn cmd = new DbCommandSyn(); //设置命令的连接 cmd.Connection = conn; //设置SQL语句,可以是存储过程 cmd.CommandText = "SELECT [Id],[Name] FROM [T_Test]"; //设置命令类型,一般SQL语句是Text,存储过程是StoredProcedure cmd.CommandType = DbCommandType.Text; //设置执行类型 cmd.ExecuteType = DbExecuteType.Reader; //执行命令,得到结果 DbCommandExecuteResult result = cmd.Execute(); if (!string.IsNullOrEmpty(result.ErrMsg))//首先判断ErrMsg是否有值,有表示执行过程发生错误 { MessageBox.Show("发生错误:" + result.ErrMsg); } else { List<T_Test> valueList = result.ReaderResult.ToEntityList<T_Test>(); //将数据显示在DataGrid中 this.dataGrid1.ItemsSource = valueList; } } catch (Exception ex) { MessageBox.Show("发生错误:" + ex.ToString()); } 2、存储过程示例 try { //数据库创建T_SQL脚本在网站App_Data文件夹下面,文件名为OMSDB.sql DbConnection conn = new DbConnection("Server=localhost;DataBase=OMSDB;Uid=sa;Pwd=jiton;"); DbCommandSyn cmd = new DbCommandSyn(); cmd.Connection = conn; //设置存储过程名称 cmd.CommandText = "JP_GetSystemName"; //设置命令类型为存储过程 cmd.CommandType = DbCommandType.StoredProcedure; cmd.ExecuteType = DbExecuteType.Scalar; //执行命令,得到结果 DbCommandExecuteResult result = cmd.Execute(); if (!string.IsNullOrEmpty(result.ErrMsg))//首先判断是否存在错误 { MessageBox.Show("发生错误:" + result.ErrMsg); } else { MessageBox.Show("系统名称为:" + result.ScalarResult as string); } } catch (Exception ex) { MessageBox.Show("发生错误:" + ex.Message); } 三、技术交流 有任何问题可以加入唯一指定的专用QQ群153079750进行反馈交流,也欢迎加入笔者的另一个Silverlight技术群175213051进行交流。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值