我有一个大的ADO.Net数据集和两个具有不同约束的数据库模式(Oracle)。数据集将与任一模式一起使用,但我希望能够在运行时告诉数据集使用哪个模式(通过连接字符串)。

这甚至可能吗?

有帮助吗?

解决方案

在.Net 2.0世界中,您可以在运行时更改表适配器上的连接字符串。您只需确保Connnection属性是公共的,可以从数据集设计器中设置。

其他提示

数据集不知道他们指向的数据库 - 它们只是数据的容器。如果数据集中填充了数据适配器,那么正如@Austin Salonen指出的那样,您可以在适配器端更改它。

这是关于如何在运行时更新连接字符串的代码片段。生成数据集的内容无关紧要。

            DataSet ds = new DataSet();

            // Do some updateing here

            // Put your connection string here dyanmiclly
            System.Data.OleDb.OleDbCommand command = new System.Data.OleDb.OleDbCommand("Your Runtime Connection String");

            // Create the data Adapter
            System.Data.OleDb.OleDbDataAdapter dataAdapter = new System.Data.OleDb.OleDbDataAdapter(command);

            // Update the dataset
            dataAdapter.Update(ds);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top