我的 App.config 中有以下内容,如何使下面的代码工作????
configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="WpfDatabind3.Properties.Settings.cbfSQL1ConnectionString"
connectionString="Data Source=STEPHANS-PC\SQLEXPRESS;Initial Catalog=cbfSQL1;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
我不知道如何访问 App.config 中的连接字符串。
DataSet myDataSet;
private void OnInit(object sender, EventArgs e)
{
string mdbFile = Path.Combine(AppDataPath, "BookData.mdb");
string connString = string.Format(
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source={0}", mdbFile);
OleDbConnection conn = new OleDbConnection(connString);
OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT * FROM BookTable;", conn);
myDataSet = new DataSet();
adapter.Fill(myDataSet, "BookTable");
// myListBox is a ListBox control.
// Set the DataContext of the ListBox to myDataSet
myListBox.DataContext = myDataSet;
}