Gets or sets the name of the .NET Framework data provider that the SqlDataSource control uses to connect to an underlying data source.
Namespace:
System.Web.UI.WebControls
Assembly:
System.Web (in System.Web.dll)
Visual Basic (Declaration)
<TypeConverterAttribute("System.Web.UI.Design.WebControls.DataProviderNameConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")> _
Public Overridable Property ProviderName As String
Dim instance As SqlDataSource
Dim value As String
value = instance.ProviderName
instance.ProviderName = value
[TypeConverterAttribute("System.Web.UI.Design.WebControls.DataProviderNameConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public virtual string ProviderName { get; set; }
[TypeConverterAttribute(L"System.Web.UI.Design.WebControls.DataProviderNameConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")]
public:
virtual property String^ ProviderName {
String^ get ();
void set (String^ value);
}
public function get ProviderName () : String
public function set ProviderName (value : String)
<asp:SqlDataSource ProviderName="String" />
Property Value
Type:
System..::.StringThe name of the data provider that the SqlDataSource uses; otherwise, the ADO.NET provider for Microsoft SQL Server, if no provider is set. The default is the ADO.NET provider for Microsoft SQL Server.
The .NET Framework includes the following data providers:
The ProviderName property is never set to the name of an unmanaged ADO.NET provider, such as MSDAORA. For more information, see Selecting Data Using the SqlDataSource Control.
If you change the ProviderName property, the DataSourceChanged event is raised, causing any controls that are bound to the SqlDataSource to rebind.
A list of available providers is specified in the DbProviderFactories subsection of the system.data section of the Machine.config file.
This section contains two code examples. The first code demonstrates how to connect to a SQL Server database using the default .NET Framework Data Provider for SQL Server for the SqlDataSource control, the System.Data.SqlClient. The second code example demonstrates how to connect to an ODBC database using the .NET Framework Data Provider for ODBC, the System.Data.Odbc.
The following code example demonstrates how to connect to a SQL Server database using the default data provider for the SqlDataSource control, the System.Data.SqlClient. Whenever the ProviderName property is not explicitly set, the default provider is used. The ConnectionString property is provider-specific.
<%@ Page language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<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="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<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>
The following code example, which is functionally the same as the preceding code example, demonstrates how to connect to an ODBC database using the .NET Framework Data Provider for ODBC, the System.Data.Odbc. The ConnectionString property is set to the name of an ODBC data source name (DSN) that is used to connect to the ODBC database.
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<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>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
<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>
Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
.NET Framework
Supported in: 3.5, 3.0, 2.0
Reference
Other Resources