類
public string GetConStr()
{
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Server.MapPath("App_Data\config.xml"));
XmlNode node1 = xmlDoc.SelectSingleNode("configuration/ConnectionStrings1/DataSource");
XmlNode node2 = xmlDoc.SelectSingleNode("configuration/ConnectionStrings1/uid");
XmlNode node3 = xmlDoc.SelectSingleNode("configuration/ConnectionStrings1/pwd");
string strcon = "Data Source=" + node1.InnerText + ";uid=" + node2.InnerText + ";pwd=" + node3.InnerText;
return strcon;
}
catch
{
Response.Redirect("Config.aspx");
return null;
}
}
調用
IConfig iconfig = new IConfig();
iconfig .GetConStr();