Changing dataset connection string at runtime

南楼画角 提交于 2019-11-29 18:15:16

问题


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:


You can modify a single instance of the table adapter.

_myAdapter.Connection.ConnectionString = connectionString;



回答2:


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

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


来源:https://stackoverflow.com/questions/3477544/changing-dataset-connection-string-at-runtime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!