asp.net 2.0 中引用Web.config内的连接字符串的方法

Web.config内容:
<appSettings>
//<add   key="SocutDataLink"   value="路径"/>   
<add   key="DataLink"   value="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Inetpub\wwwroot\App_Data\ASPNetDB.mdb"/>
</appSettings>

引用地方的内容:
string strConnection = ConfigurationManager.AppSettings["DataLink"].ToString();  

例子:
string strConnection = ConfigurationManager.AppSettings["DataLink"].ToString(); 
OleDbConnection con = new OleDbConnection(strConnection);
string str= "sql语句";
con.Open();
OleDbCommand cmd = new OleDbCommand(str, con);
cmd.ExecuteNonQuery();
con.Close();

你可能感兴趣的:(asp.net)