SqlDataSource.ProviderName Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta il nome del provider di dati .NET Framework utilizzato dal controllo SqlDataSource per la connessione a un'origine dati sottostante.
public:
virtual property System::String ^ ProviderName { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.DataProviderNameConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual string ProviderName { get; set; }
[System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.DataProviderNameConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual string ProviderName { get; set; }
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.DataProviderNameConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.ProviderName : string with get, set
[<System.ComponentModel.TypeConverter("System.Web.UI.Design.WebControls.DataProviderNameConverter, System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")>]
member this.ProviderName : string with get, set
Public Overridable Property ProviderName As String
Valore della proprietà
Nome del provider di dati utilizzato dall'oggetto SqlDataSource; in caso contrario, il provider ADO.NET per Microsoft SQL Server, se non è impostato alcun provider. Il valore predefinito è il provider ADO.NET per Microsoft SQL Server.
- Attributi
Esempio
In questa sezione sono riportati due esempi di codice. Il primo codice illustra come connettersi a un database SQL Server usando il provider di dati .NET Framework predefinito per SQL Server per il SqlDataSource controllo , .System.Data.SqlClient Nel secondo esempio di codice viene illustrato come connettersi a un database ODBC usando il provider di dati .NET Framework per ODBC, ovvero System.Data.Odbc.
Nell'esempio di codice seguente viene illustrato come connettersi a un database SQL Server usando il provider di dati predefinito per il SqlDataSource controllo , ovvero System.Data.SqlClient. Ogni volta che la ProviderName proprietà non è impostata in modo esplicito, viene utilizzato il provider predefinito. La ConnectionString proprietà è specifica del provider.
<%@ 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 LastName FROM Employees">
</asp:SqlDataSource>
<asp:ListBox
id="ListBox1"
runat="server"
DataTextField="LastName"
DataSourceID="SqlDataSource1">
</asp:ListBox>
</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 LastName FROM Employees">
</asp:SqlDataSource>
<asp:ListBox
id="ListBox1"
runat="server"
DataTextField="LastName"
DataSourceID="SqlDataSource1">
</asp:ListBox>
</form>
</body>
</html>
Nell'esempio di codice seguente, che è funzionalmente uguale all'esempio di codice precedente, viene illustrato come connettersi a un database ODBC usando il provider di dati .NET Framework per ODBC, .System.Data.Odbc La ConnectionString proprietà viene impostata sul nome di un nome di origine dati ODBC (DSN) utilizzato per connettersi al database ODBC.
<!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>
<!-- This example uses a Northwind database that is hosted by an ODBC-compliant
database. To run this sample, create an ODBC DSN to any database that hosts
the Northwind database, including Microsoft SQL Server or Microsoft Access,
change the name of the DSN in the ConnectionString, and view the page.
-->
<form id="form1" runat="server">
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
ProviderName="System.Data.Odbc"
ConnectionString="dsn=myodbc3dsn;"
SelectCommand="SELECT LastName FROM Employees;">
</asp:SqlDataSource>
<asp:ListBox
id="ListBox1"
runat="server"
DataSourceID="SqlDataSource1"
DataTextField="LastName">
</asp:ListBox>
</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>
<!-- This example uses a Northwind database that is hosted by an ODBC-compliant
database. To run this sample, create an ODBC DSN to any database that hosts
the Northwind database, including Microsoft SQL Server or Microsoft Access,
change the name of the DSN in the ConnectionString, and view the page.
-->
<form id="form1" runat="server">
<asp:SqlDataSource
id="SqlDataSource1"
runat="server"
ProviderName="System.Data.Odbc"
ConnectionString="dsn=myodbc3-test;"
SelectCommand="SELECT LastName FROM Employees;">
</asp:SqlDataSource>
<asp:ListBox
id="ListBox1"
runat="server"
DataSourceID="SqlDataSource1"
DataTextField="LastName">
</asp:ListBox>
</form>
</body>
</html>
Commenti
.NET Framework include i provider di dati seguenti:
Il System.Data.SqlClient provider è il provider di dati .NET Framework predefinito per SQL Server.
Il System.Data.OleDb provider è il provider di dati .NET Framework per OLE DB.
Il System.Data.Odbc provider è il provider di dati .NET Framework per ODBC.
Il System.Data.OracleClient provider è il provider di dati .NET Framework per Oracle.
La ProviderName proprietà non viene mai impostata sul nome di un provider di ADO.NET non gestito, ad esempio MSDAORA
. Per altre informazioni, vedere Selezione di dati tramite il controllo SqlDataSource.
Se si modifica la ProviderName proprietà , viene generato l'evento DataSourceChanged , causando la riassociazione di tutti i controlli associati all'oggetto SqlDataSource .
Un elenco dei provider disponibili viene specificato nella DbProviderFactories
sottosezione della system.data
sezione del file Machine.config.
Si applica a
Vedi anche
Commenti e suggerimenti
https://aka.ms/ContentUserFeedback.
Presto disponibile: Nel corso del 2024 verranno gradualmente disattivati i problemi di GitHub come meccanismo di feedback per il contenuto e ciò verrà sostituito con un nuovo sistema di feedback. Per altre informazioni, vedereInvia e visualizza il feedback per