ConfigurationManager.ConnectionStrings 未将对象引用设置到对象的实例. 5
MainWindow.xaml是usingSystem;usingSystem.Collections.Generic;usingSystem.Configuration...
MainWindow.xaml是
using System;using System.Collections.Generic;using System.Configuration;using System.Data.SqlClient;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;
namespace ADO.Net{ /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); }
private void BT_OK_Click(object sender, RoutedEventArgs e) { string connStr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString; MessageBox.Show(connStr); } }}
配置文件是
<?xml version="1.0" encoding="utf-8" ?><configuration> <connectionStrings> <add name="dbConnStr" connectionString="Data Source=.; Initial Catalog=MyTest;User ID=sa;Password=123456"/> </connectionStrings></configuration>
但是出现这个异常,一直没办法解决 T^T 展开
using System;using System.Collections.Generic;using System.Configuration;using System.Data.SqlClient;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;
namespace ADO.Net{ /// <summary> /// MainWindow.xaml 的交互逻辑 /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); }
private void BT_OK_Click(object sender, RoutedEventArgs e) { string connStr = ConfigurationManager.ConnectionStrings["dbConnStr"].ConnectionString; MessageBox.Show(connStr); } }}
配置文件是
<?xml version="1.0" encoding="utf-8" ?><configuration> <connectionStrings> <add name="dbConnStr" connectionString="Data Source=.; Initial Catalog=MyTest;User ID=sa;Password=123456"/> </connectionStrings></configuration>
但是出现这个异常,一直没办法解决 T^T 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询