ConnectionStringsExpressionBuilder 类
定义
检索或生成代码以检索 Web.config 文件的 <connectionStrings> 节中的值。Retrieves, or generates code to retrieve, values from the <connectionStrings> section of the Web.config file.
public ref class ConnectionStringsExpressionBuilder : System::Web::Compilation::ExpressionBuilder
public class ConnectionStringsExpressionBuilder : System.Web.Compilation.ExpressionBuilder
type ConnectionStringsExpressionBuilder = class
inherit ExpressionBuilder
Public Class ConnectionStringsExpressionBuilder
Inherits ExpressionBuilder
- 继承
示例
下面的代码示例演示如何以声明方式使用 SqlDataSource 控件从运行 Microsoft SQL Server 的计算机中检索数据,并在控件中显示该数据 GridView 。The following code example demonstrates how to declaratively use a SqlDataSource control to retrieve data from a computer running Microsoft SQL Server and display it in a GridView control.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
DataSourceMode="DataReader"
ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
SelectCommand="SELECT FirstName, LastName, Title FROM Employees">
</asp:SqlDataSource>
<asp:GridView
id="GridView1"
runat="server"
DataSourceID="SqlDataSource1">
</asp:GridView>
</form>
</body>
</html>
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
DataSourceMode="DataReader"
ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
SelectCommand="SELECT FirstName, LastName, Title FROM Employees">
</asp:SqlDataSource>
<asp:GridView
id="GridView1"
runat="server"
DataSourceID="SqlDataSource1">
</asp:GridView>
</form>
</body>
</html>
此代码从 Web.config 文件中检索以下连接字符串。The code retrieves the following connection string from the Web.config file.
<configuration xmlns="http://schemas.microsoft.com/.NetConfiguration/v2.0">
<connectionStrings>
<add name="MyNorthwind" connectionString="Data
Source=localhost;Integrated Security=SSPI;Initial
Catalog=Northwind;" providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
注解
ConnectionStringsExpressionBuilder类提供对 Web.config 文件的节中的值的访问 <connectionStrings> 。The ConnectionStringsExpressionBuilder class provides access to values in the <connectionStrings> section of the Web.config file. <connectionStrings>Web.config 文件的部分包含名称/值对中的连接字符串值。The <connectionStrings> section of the Web.config file contains connection string values in name/value pairs.
通过分配窗体的表达式来检索连接字符串值A connection string value is retrieved by assigning an expression of the form
<%$ ConnectionStrings: secureConnectionString %>
到控件属性。to a control property. 冒号 (: ) 指定要检索的表达式的类型,而冒号后面的部分表示连接字符串的名称。The part of the expression before the colon (:) designates the type of expression to be retrieved, and the part after the colon signifies the name of the connection string. 前面的表达式将从 Web.config 文件中检索以下值。The preceding expression would retrieve the following value from the Web.config file.
<connectionStrings>
<add name="secureConnectionString" connectionString="Data
Source=localhost;Integrated Security=SSPI;Initial
Catalog=Northwind;" providerName="System.Data.SqlClient" />
</connectionStrings>
当页分析器遇到带有前缀的表达式时 ConnectionStrings ,它将创建类的一个实例 ConnectionStringsExpressionBuilder 来处理该表达式。When the page parser encounters an expression with the prefix ConnectionStrings, it creates an instance of the ConnectionStringsExpressionBuilder class to handle the expression.
如果在要编译的页面中遇到表达式,则 ConnectionStringsExpressionBuilder 对象将生成用于从 Web.config 文件中检索指定连接字符串的代码。If the expression is encountered in a page that will be compiled, the ConnectionStringsExpressionBuilder object generates code that retrieves the specified connection string from the Web.config file. 如果在不进行编译的页面中遇到表达式,则在 ConnectionStringsExpressionBuilder 分析页面时,对象将返回 Web.config 文件中的值。If the expression is encountered in a page that will not be compiled, the ConnectionStringsExpressionBuilder object returns the value from the Web.config file when the page is parsed.
构造函数
| ConnectionStringsExpressionBuilder() |
初始化 ConnectionStringsExpressionBuilder 类的新实例。Initializes a new instance of the ConnectionStringsExpressionBuilder class. |
属性
| SupportsEvaluate |
返回一个值,该值指示是否可在不编译的页中计算表达式。Returns a value indicating whether an expression can be evaluated in a page that is not compiled. |
方法
| Equals(Object) |
确定指定对象是否等于当前对象。Determines whether the specified object is equal to the current object. (继承自 Object) |
| EvaluateExpression(Object, BoundPropertyEntry, Object, ExpressionBuilderContext) |
从 Web.config 文件的 < |
| GetCodeExpression(BoundPropertyEntry, Object, ExpressionBuilderContext) |
返回在页分析过程中要计算的代码表达式。Returns a code expression to evaluate during page parsing. |
| GetConnectionString(String) |
从 Web.config 文件的 < |
| GetConnectionStringProviderName(String) |
从 Web.config 文件的 < |
| GetHashCode() |
作为默认哈希函数。Serves as the default hash function. (继承自 Object) |
| GetType() |
获取当前实例的 Type。Gets the Type of the current instance. (继承自 Object) |
| MemberwiseClone() |
创建当前 Object 的浅表副本。Creates a shallow copy of the current Object. (继承自 Object) |
| ParseExpression(String, Type, ExpressionBuilderContext) |
返回一个表示通过分析得出的表达式的对象。Returns an object that represents the parsed expression. |
| ToString() |
返回表示当前对象的字符串。Returns a string that represents the current object. (继承自 Object) |