Reputation: 1644
Is there any way to get the SqlConnection
from an SqlDataAdapter
?
I had expected to find an SqlDataAdapter.Connection
property.
Upvotes: 2
Views: 123
Reputation: 1527
You can get it from relevant SqlCommand.
Depending on which one of the is set:
adapter.SelectCommand.Connection;
adapter.InsertCommand.Connection;
adapter.UpdateCommand.Connection;
adapter.DeleteCommand.Connection;
Upvotes: 3
Reputation: 11964
Use this:
var da = new SqlDataAdapter();
....
string connectionString = da.SelectCommand.Connection.ConnectionString
Upvotes: 1
Reputation: 19296
SqlDataAdapter
has property SelectCommand
(type of SqlCommand
) and SelectCommand
has property Connection
(type of SqlConnection
).
Upvotes: 3
Reputation: 26940
Look at the SelectCommand
or whichever command you're interested in.
Upvotes: 4