首页 > 代码库 > EF运用成ADO.NET操作返回DataSet或者DataTable
EF运用成ADO.NET操作返回DataSet或者DataTable
#region 获取DataSet返回结构集 public DataSet GetDataSet(string sql, params SqlParameter[] para) { for (int i = 0; i < para.Length; i++) { SqlParameter p = para[i]; sql += " " + p.ParameterName + ","; } sql = sql.Substring(0, sql.Length - 1); DataSet sd = new DataSet(); using (var db = new BaseContext()) { SqlConnection conn = db.Database.Connection as SqlConnection; using (SqlCommand cmd = new SqlCommand(sql, conn)) { cmd.Parameters.AddRange(para); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(sd); } } return sd; } #endregion #region 获取Table返回DataTable public DataTable GetDataTable(string sql, params SqlParameter[] para) { DataTable dt=new DataTable(); for (int i = 0; i < para.Length; i++) { SqlParameter p = para[i]; sql += " " + p.ParameterName + ","; } sql = sql.Substring(0, sql.Length - 1); using (var db = new BaseContext()) { SqlConnection conn = db.Database.Connection as SqlConnection; using (SqlCommand cmd=new SqlCommand(sql,conn)) { cmd.Parameters.AddRange(para); SqlDataAdapter sda = new SqlDataAdapter(cmd); sda.Fill(dt); return dt; } } } #endregion
EF运用成ADO.NET操作返回DataSet或者DataTable
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。