首页 > 代码库 > EF 返回DataTable 扩展方法
EF 返回DataTable 扩展方法
public static class EFExtendMethod { public static DataTable SqlQueryToDataTable(this Database db, string sql, CommandType type = CommandType.Text, params SqlParameter[] param) { DataTable ret_dt = new DataTable(); SqlConnection conn = db.Connection as SqlConnection; if (conn == null) { conn = new SqlConnection(db.Connection.ConnectionString); } if (conn.State != ConnectionState.Open) { conn.Open(); } try { SqlCommand cmd = new SqlCommand(sql, conn); cmd.CommandType = type; if (param != null && param.Length > 0) { foreach (SqlParameter p in param) { cmd.Parameters.Add(p); } } SqlDataAdapter adapter = new SqlDataAdapter(cmd); adapter.Fill(ret_dt); conn.Close(); return ret_dt; } catch (Exception ex) { conn.Close(); return ret_dt; } } public static DataTable SqlQueryToDataTable(this Database db, string sql, params SqlParameter[] param) { return SqlQueryToDataTable(db,sql,CommandType.Text,param); } }
EF 返回DataTable 扩展方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。