Share via


AccessDataSource.ConnectionString 屬性

定義

取得連接字串,用於連接 Microsoft Access 資料庫。

public:
 virtual property System::String ^ ConnectionString { System::String ^ get(); void set(System::String ^ value); };
[System.ComponentModel.Browsable(false)]
public override string ConnectionString { get; set; }
[<System.ComponentModel.Browsable(false)>]
member this.ConnectionString : string with get, set
Public Overrides Property ConnectionString As String

屬性值

String

OLE DB 連接字串,AccessDataSource 控制項會用來透過 System.Data.OleDb .NET 資料提供者連接 Access 資料庫。

屬性

例外狀況

已嘗試設定 ConnectionString 屬性。

範例

下列程式碼範例示範如何在 ASP.NET 網頁中顯示 ConnectionString 控制項的 AccessDataSource 屬性。

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
private void Page_Load(Object sender, EventArgs e) {
  Label1.Text = AccessDataSource1.ConnectionString;
}
</script>

<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"
        DataFile="Northwind.mdb">
      </asp:AccessDataSource>

      <asp:Label
        id="Label1"
        runat="server">
      </asp:Label>

    </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">

<script runat="server">
Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

  Label1.Text = AccessDataSource1.ConnectionString

End Sub 'Page_Load
</script>

<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"
        DataFile="Northwind.mdb">
      </asp:AccessDataSource>

      <asp:Label
        id="Label1"
        runat="server">
      </asp:Label>

    </form>
  </body>
</html>

備註

控制項 AccessDataSource 只能與 .NET 資料提供者搭配 System.Data.OleDb 使用,而使用的連接字串 AccessDataSource 是這個提供者特有的。 因此, AccessDataSource 控制項會公開連接字串設定,例如 DataFile 屬性,並在執行時間使用 屬性的值 ConnectionString 來建構連接字串。如果已設定,則為 。

適用於

另請參閱