DanDan
DanDan

Reputation: 10562

Changing dataset connection string at runtime

I have a c# generated dataset. How can I change the connection string so I can use the dataset with another (identically structured yet differently populated) database? This has to occur at runtime as I do not know the server or database name at compile time. I am using c# 2.0.

Upvotes: 11

Views: 27439

Answers (3)

George Hahn
George Hahn

Reputation: 11

The database name is also a parameter in the connection string.

Upvotes: 0

Quentamia
Quentamia

Reputation: 3292

You can modify a single instance of the table adapter.

_myAdapter.Connection.ConnectionString = connectionString;

Upvotes: 10

DanDan
DanDan

Reputation: 10562

Based on the link above, I did it this way:

partial class QueriesTableAdapter
{
    public QueriesTableAdapter(string connectionString)
    {
        Properties.Settings.Default["connectionString"] = connectionString;
    }
}

Upvotes: 7

Related Questions