/// <summary>
/// 获取DataTable
/// </summary>
/// <param name="sql"></param>
/// <param name="connection"></param>
/// <returns></returns>
public static DataTable GetDataTable(string sql, IDbConnection connection = null)
{
DataTable dt = new DataTable();
try
{
using (var conn = connection ?? DBHelper.GetConnection())
{
if (conn.State != ConnectionState.Open)
{
conn.Open();
}
IDbCommand command = conn.CreateCommand();
command.CommandText = sql;
using (var reader = command.ExecuteReader())
{
dt.Load(reader);
}
}
return dt;
}
catch (Exception)
{
throw;
}
}
C# IDBConnection 获取DataTable
最新推荐文章于 2023-02-24 16:04:34 发布