一、升级说明
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.ScalarResultas string);
}
}
catch (Exception ex)
{
MessageBox.Show("发生错误:" + ex.Message);
}
三、技术交流
有任何问题可以加入唯一指定的专用QQ群153079750进行反馈交流,也欢迎加入笔者的另一个Silverlight技术群175213051进行交流。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。