Best way to set strongly typed dataset connection string at runtime?

后端 未结 7 1744
孤街浪徒
孤街浪徒 2021-02-20 01:19

My Windows Forms application uses a strongly typed dataset created using the designer in Visual Studio. At runtime I would like to be able to select either the live or test data

7条回答
  •  北海茫月
    2021-02-20 01:54

    By default the Connection property is set to be internal. This can be changed in the DataSet's designer.

    1. Right-click the TableAdapter.

    1. Then change the ConnectionModifier property to public.

    1. You can now access the Connection property in your project.
    var loginsTableAdapter = new MyDataSetTableAdapters.LoginsTableAdapter();
    loginsTableAdapter.Connection.ConnectionString = _myConnectionString;
    

提交回复
热议问题