AccessDataSource controle de servidor Web Declarative sintaxe
Representa um dados controle do código-fonte que funciona com bancos de dados do Microsoft acesso.
<asp:AccessDataSource
CacheDuration="string|Infinite"
CacheExpirationPolicy="Absolute|Sliding"
CacheKeyDependency="string"
CancelSelectOnNullParameter="True|False"
ConflictDetection="OverwriteChanges|CompareAllValues"
DataFile="uri"
DataSourceMode="DataReader|DataSet"
DeleteCommand="string"
DeleteCommandType="Text|StoredProcedure"
EnableCaching="True|False"
EnableTheming="True|False"
EnableViewState="True|False"
FilterExpression="string"
ID="string"
InsertCommand="string"
InsertCommandType="Text|StoredProcedure"
OldValuesParameterFormatString="string"
OnDataBinding="DataBinding event handler"
OnDeleted="Deleted event handler"
OnDeleting="Deleting event handler"
OnDisposed="Disposed event handler"
OnFiltering="Filtering event handler"
OnInit="Init event handler"
OnInserted="Inserted event handler"
OnInserting="Inserting event handler"
OnLoad="Load event handler"
OnPreRender="PreRender event handler"
OnSelected="Selected event handler"
OnSelecting="Selecting event handler"
OnUnload="Unload event handler"
OnUpdated="Updated event handler"
OnUpdating="Updating event handler"
runat="server"
SelectCommand="string"
SelectCommandType="Text|StoredProcedure"
SkinID="string"
SortParameterName="string"
UpdateCommand="string"
UpdateCommandType="Text|StoredProcedure"
Visible="True|False"
>
<DeleteParameters>
<asp:ControlParameter
ControlID="string"
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|
ReturnValue"
Name="string"
PropertyName="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:CookieParameter
ConvertEmptyStringToNull="True|False"
CookieName="string"
DefaultValue="string"
Direction="Input|Output|InputOutput|
ReturnValue"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:FormParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
FormField="string"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:Parameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64
|Single|Double|Decimal|DateTime|String"
/>
<asp:ProfileParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
PropertyName="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:QueryStringParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
QueryStringField="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:SessionParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
SessionField="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
</DeleteParameters>
<FilterParameters>
<asp:ControlParameter
ControlID="string"
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
PropertyName="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:CookieParameter
ConvertEmptyStringToNull="True|False"
CookieName="string"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:FormParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
FormField="string"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:Parameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:ProfileParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
PropertyName="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:QueryStringParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
QueryStringField="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:SessionParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
SessionField="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
</FilterParameters>
<InsertParameters>
<asp:ControlParameter
ControlID="string"
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
PropertyName="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:CookieParameter
ConvertEmptyStringToNull="True|False"
CookieName="string"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:FormParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
FormField="string"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:Parameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:ProfileParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
PropertyName="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:QueryStringParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
QueryStringField="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:SessionParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
SessionField="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
</InsertParameters>
<SelectParameters>
<asp:ControlParameter
ControlID="string"
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
PropertyName="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:CookieParameter
ConvertEmptyStringToNull="True|False"
CookieName="string"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:FormParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
FormField="string"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:Parameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:ProfileParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
PropertyName="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:QueryStringParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
QueryStringField="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:SessionParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
SessionField="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
</SelectParameters>
<UpdateParameters>
<asp:ControlParameter
ControlID="string"
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
PropertyName="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:CookieParameter
ConvertEmptyStringToNull="True|False"
CookieName="string"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:FormParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
FormField="string"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:Parameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:ProfileParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
PropertyName="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:QueryStringParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
QueryStringField="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
<asp:SessionParameter
ConvertEmptyStringToNull="True|False"
DefaultValue="string"
Direction="Input|Output|InputOutput|ReturnValue"
Name="string"
SessionField="string"
Size="integer"
Type="Empty|Object|DBNull|Boolean|Char|SByte|
Byte|Int16|UInt16|Int32|UInt32|Int64|UInt64|
Single|Double|Decimal|DateTime|String"
/>
</UpdateParameters>
</asp:AccessDataSource>
Comentários
The AccessDataSource classe é um controle de fonte de dados que funciona com bancos de dados do Microsoft acesso. Como sua classe base, SqlDataSource, o AccessDataSource controle usa consultas SQL para executar a recuperação de dados.
Uma das características exclusivas do AccessDataSource controle é que você não fizer isso conjunto o ConnectionString propriedade. Tudo o que você precisa fazer é conjunto o local do arquivo .mdb do acesso, usando o DataFile propriedade e o AccessDataSource se encarrega da conexão com o banco de dados subjacente. Você deve colocar bancos de dados do acesso no diretório App_Data do site e referenciá-los por um caminho relativo (por exemplo, ~/App_Data/Northwind.mdb). Este local oferece segurança adicional para arquivos de dados, porque não são servidos se forem solicitadas diretamente pelo navegador da Web cliente.
The AccessDataSource classe não suporta conexão a bancos de dados do acesso protegidos por um nome de usuário ou senha, porque não é possível conjunto o ConnectionString propriedade. Se seu banco de dados do acesso estiver protegido por um nome de usuário ou senha, use o SqlDataSource controle para se conectar a ele para que você pode especificar uma seqüência de caracteres de conexão completa.
Você BIND controles ligados a dados a um AccessDataSource usando o DataSourceID propriedade do controle limite a dados. Para obter mais informações sobre vinculação um controle limite a dados a controles de fonte de dados, consulte Ligação a dados usando o controle de fonte de dados.
Para obter mais informações sobre como usar o AccessDataSource controle, consulte Visão Geral do Controle de Servidor Web AccessDataSource.
Exemplo
O exemplo de código a seguir demonstra uma situação de atualização com o e exibição comunsGridView controle. The SelectCommand propriedade é conjunto a uma consulta SQL apropriada e dados do Northwind banco de dados é exibido na GridView controle. Porque um UpdateCommand também é especificado e o AutoGenerateEditButton é definido como true, você pode edição e atualizar os registros com nenhum código adicional. The GridView adicionando parâmetros para alças de controle de UpdateParameters coleção; o GridView passa os valores de parâmetro para o BoundField objetos primeiro, seguido dos valores dos campos que são especificados clicando-se a DataKeyNames propriedade. The GridView chamadas a Update método automaticamente. Para solicitar os parâmetros, explicitamente especificar um UpdateParameters coleta na AccessDataSource objeto.
<%@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:accessdatasource
id="AccessDataSource1"
runat="server"
datasourcemode="DataSet"
datafile="~/App_Data/Northwind.mdb"
selectcommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
updatecommand="Update Employees SET FirstName=?,LastName=?,Title=? WHERE EmployeeID=@EmployeeID">
</asp:accessdatasource>
<asp:gridview
id="GridView1"
runat="server"
autogeneratecolumns="False"
datakeynames="EmployeeID"
autogenerateeditbutton="True"
datasourceid="AccessDataSource1">
<columns>
<asp:boundfield headertext="First Name" datafield="FirstName" />
<asp:boundfield headertext="Last Name" datafield="LastName" />
<asp:boundfield headertext="Title" datafield="Title" />
</columns>
</asp:gridview>
</form>
</body>
</html>
<%@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:accessdatasource
id="AccessDataSource1"
runat="server"
datasourcemode="DataSet"
datafile="~/App_Data/Northwind.mdb"
selectcommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
updatecommand="Update Employees SET FirstName=?,LastName=?,Title=? WHERE EmployeeID=@EmployeeID">
</asp:accessdatasource>
<asp:gridview
id="GridView1"
runat="server"
autogeneratecolumns="False"
datakeynames="EmployeeID"
autogenerateeditbutton="True"
datasourceid="AccessDataSource1">
<columns>
<asp:boundfield headertext="First Name" datafield="FirstName" />
<asp:boundfield headertext="Last Name" datafield="LastName" />
<asp:boundfield headertext="Title" datafield="Title" />
</columns>
</asp:gridview>
</form>
</body>
</html>
<%@Page Language="VJ#" %>
<!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:AccessDataSource
id="AccessDataSource1"
runat="server"
DataSourceMode="DataSet"
DataFile="~/App_Data/Northwind.mdb"
SelectCommand="SELECT EmployeeID,FirstName,LastName,Title FROM Employees"
UpdateCommand="Update Employees SET FirstName=@FirstName,LastName=@LastName,Title=@Title WHERE EmployeeID=@EmployeeID">
</asp:AccessDataSource>
<asp:GridView
id="GridView1"
runat="server"
AutoGenerateColumns="False"
DataKeyNames="EmployeeID"
AutoGenerateEditButton="True"
DataSourceID="AccessDataSource1">
<Columns>
<asp:BoundField HeaderText="First Name" DataField="FirstName" />
<asp:BoundField HeaderText="Last Name" DataField="LastName" />
<asp:BoundField HeaderText="Title" DataField="Title" />
</Columns>
</asp:GridView>
</form>
</body>
</html>