I have an instance of IDbConnection, which can be any connection, Sql, OleDb, etc. I want to make a generic wrapper so I can just send the wrapper a connection and get a nice set of methods for easy manipulation. I have a Query method, I want it to return a DataTable, so I can do
IDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = myCommand;
DataSet ds = new DataSet();
adapter.Fill(ds);
The problem is I have to use OleDbAdapter and it wouldn t work for SQL, I don t really want to write "driver specific" code. Is there a way I can get a IDataAdapter instance from my instantiated IDbConnection object? I know I can create a command doing
IDbCommand command = _connection.CreateCommand();
认为对IDataAdapter来说 一定有简单的方法来做同样的事情, 这是合乎逻辑的。
编辑:
using (var reader = command.ExecuteReader())
{
var dataTable = new DataTable();
dataTable.Load(reader);
}
与其说是我要求的 不如说是个不错的解决方案