⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webconfigexample.aspx

📁 asp.net专家200问(含源代码解决法案
💻 ASPX
字号:

<% @Import Namespace="System.Data" %>
<% @Import Namespace="System.Data.SqlClient" %>
<HTML>
	<HEAD>
		<title>使用ConfigurationSettings.AppSettings属性读取自定义配置节示例</title>

		<script language="C#" runat="server">

			void Page_Load(object sender, System.EventArgs e)
			{
				// 从<appSettings>节读取连接字符串
				string ConnString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSqlServer"];

				// 创建SqlConnection对象
				SqlConnection thisConnection = new SqlConnection(ConnString);

				try
				{
					// 打开连接
					thisConnection.Open();
					Label1.Text = "连接已经打开";
				}
				catch(Exception ex)
				{
					Label1.Text = ex.ToString();
				}
				finally
				{
					// 关闭连接
					thisConnection.Close();
				}
			}

		</script>
		
	</HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
			<h3>使用ConfigurationSettings.AppSettings属性读取自定义配置节示例</h3>
			<asp:Label id="Label1" runat="server">Label</asp:Label>
		</form>
	</body>
</HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -