2
votes

I use typed datasets in my solution (they are defined in an other project, I have only references). I want to change the Connection String at runtime. I have tried the following, but didnt work:

MyDatasetTableAdapters.MyDataTableAdapter adapter = new MyDataTableAdapter();
adapter.Connection=MySQLConnection;

same with

adapter.Connection.ConnectionString = MyConnectionString;

There is no definition for Connection.

Is there an easy way to change the connection?

Thank you!

2
adapter.SelectCommand.Connection ? - Rafael F.

2 Answers

2
votes

Change the ConnectionModifier in your MyDatasetTableAdapters to Public (the default is Internal), then you can set the ConnectionString for the adapter.

0
votes

Are you getting any exceptions?

adapter.Connection.ConnectionString = [your connection string];

This should work though what are you trying to set it to? It should be a string.

if the connection string you want to set it to is a property of the project try

adapter.Connection.ConnectionString = Properties.Settings.Default.[YourPropertyNameHere];

or if you just want to set it as a string use

adapter.Connection.ConnectionString = "YourConnectionStringHere";