EF运用成ADO.NET操作返回DataSet或者DataTable
2021-06-12 14:05
标签:params ble apt lda database ext net pre for EF运用成ADO.NET操作返回DataSet或者DataTable 标签:params ble apt lda database ext net pre for 原文地址:http://www.cnblogs.com/duanyuerui/p/7286477.html #region 获取DataSet返回结构集
public DataSet GetDataSet(string sql, params SqlParameter[] para)
{
for (int i = 0; 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 )
{
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
文章链接:http://soscw.com/index.php/essay/93893.html