views:

74

answers:

2

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.

+1  A: 

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

partial class QueriesTableAdapter
{
    public QueriesTableAdapter(string connectionString)
    {
        Properties.Settings.Default["connectionString"] = connectionString;
    }
}
DanDan
Looks like how I would have done it ... Is there a problem doing it this way?
drachenstern
Nope, seems to work quite well and a bit nicer than the link suggests above. Would still be nice to have a per-instance version though, but it's not a problem just yet.
DanDan
+1  A: 

You can modify a single instance of the table adapter.

_myAdapter.Connection.ConnectionString = connectionString;
Quenton Jones
I prefer your answer.
DanDan