IDbConnection + select -> DataTable

M

Miha Markic

There is IDbConnection.CreateCommand method to create a proper command -
which might be enough for you. However, I don't think you can create a
proper dbdataadapter out of those classes. You would need a
DbProviderFactory instance.
There is a well writen topic "Writing Provider-Independent Code in ADO.NET"
in help files that might give you further information.
 
G

Guest

That's what I found too. However the DbCommand can give me a DbDataReader
which between it and DbDataReader.GetSchema its possible to create and
populate a DataTable. So it's weird that there is no call to do so...

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




Miha Markic said:
There is IDbConnection.CreateCommand method to create a proper command -
which might be enough for you. However, I don't think you can create a
proper dbdataadapter out of those classes. You would need a
DbProviderFactory instance.
There is a well writen topic "Writing Provider-Independent Code in ADO.NET"
in help files that might give you further information.

--
Miha Markic [MVP C#, INETA Country Leader for Slovenia]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

David Thielen said:
Hi;

This should be possible but I can't figure out how to do it other than
reading each row and stuffing it into a table.

I have an IDbConnection and the select - no other info. I need a DataTable
of the data that will be returned from the select. How can I do this?

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
 
W

WenYuan Wang [MSFT]

Hi Dave,

DataTable could load rows from IDataReader. You may check DataTable.load()
method.
For Example:
IDbConnection cn = new System.Data.SqlClient.SqlConnection(....);
IDbCommand cd=cn.CreateCommand();
IDataReader dr=cd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);

Hope this helps.
Sincerely,
Wen Yuan
Microsoft Online Community Support
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top