Changing dataset connection string at runtime

后端 未结 3 1820
说谎
说谎 2021-01-02 06:14

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? Th

相关标签:
3条回答
  • 2021-01-02 06:25

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

    0 讨论(0)
  • 2021-01-02 06:35

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

    partial class QueriesTableAdapter
    {
        public QueriesTableAdapter(string connectionString)
        {
            Properties.Settings.Default["connectionString"] = connectionString;
        }
    }
    
    0 讨论(0)
  • 2021-01-02 06:44

    You can modify a single instance of the table adapter.

    _myAdapter.Connection.ConnectionString = connectionString;
    
    0 讨论(0)
提交回复
热议问题