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
2010-08-13 15:10:28
Looks like how I would have done it ... Is there a problem doing it this way?
drachenstern
2010-08-13 15:12:16
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
2010-08-13 20:23:27
+1
A:
You can modify a single instance of the table adapter.
_myAdapter.Connection.ConnectionString = connectionString;
Quenton Jones
2010-08-13 15:14:32