private void btnRead_Click(object sender, EventArgs e)
{
string str = AppDomain.CurrentDomain.BaseDirectory + "web.config";
System.Xml.XmlDocument webconfig = new System.Xml.XmlDocument();
webconfig.Load(str);//web.config的路径
System.Xml.XmlNode node = webconfig.SelectSingleNode("/configuration/connectionStrings/add[@name='SqlConnectionString']");//要找的节点
if (node == null)
{
MessageBox.Show("没有找到符合要求的节点");
}
else
{
MessageBox.Show(node.Attributes[1].InnerText);
}
}
WinForm 读取Web.config 中数据库连接字符串
最新推荐文章于 2020-10-19 16:08:09 发布