因为公司框架中的很多地方用到DataTable,直接将DataTable作为数据源绑定到DataGridView,所以为PetaPoco添加了两个方法,一个是用以填充单个DataTable,一个是用以多结果集时填充DataSet。
#region operation Fill /// <summary> /// 填充一个DataSet /// </summary> /// <param name="ds">引用的DataSet</param> /// <param name="sql">sql语句</param> /// <param name="args">参数</param> public void Fill(DataSet ds, string sql, params object[] args) { OpenSharedConnection(); try { using (var cmd = CreateCommand(_sharedConnection, sql, args)) { using (DbDataAdapter dbDataAdapter = _factory.CreateDataAdapter()) { dbDataAdapter.SelectCommand = (DbCommand)cmd; dbDataAdapter.Fill(ds); } } } finally { CloseSharedConnection(); } } /// <summary> /// 填充一个DataTable /// </summary> /// <param name="dt">DataTable的引用</param> /// <param name="sql">Sql语句</param> /// <param name="args">参数</param> public void Fill(DataTable dt, string sql, params object[] args) { OpenSharedConnection(); try { using (var cmd = CreateCommand(_sharedConnection, sql, args)) { using (DbDataAdapter dbDataAdapter = _factory.CreateDataAdapter()) { dbDataAdapter.SelectCommand = (DbCommand)cmd; dbDataAdapter.Fill(dt); } } } finally { CloseSharedConnection(); } } #endregion 本文转自齐师傅博客园博客,原文链接:http://www.cnblogs.com/youring2/archive/2012/06/20/2556456.html如需转载请自行联系原作者