AccessDataSourceDesigner.GetConnectionString 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得在設計階段有效的連接字串,以供與這個設計工具關聯的控制項使用。
protected:
override System::String ^ GetConnectionString();
protected override string GetConnectionString ();
override this.GetConnectionString : unit -> string
Protected Overrides Function GetConnectionString () As String
傳回
String,包含關聯 AccessDataSource 的設計階段連接字串。
範例
下列程式代碼範例示範如何使用 GetConnectionString 方法,在設計時間顯示與 AccessDataSource 控件佔位元中控件相關聯的 Microsoft Access 資料庫的連接字串。
此程式代碼範例是提供給 類別之較大範例的 AccessDataSourceDesigner 一部分。
// Generate design time markup.
public override string GetDesignTimeHtml()
{
// Generate a design-time placeholder containing the
// DataFile and the ConnectionString properties.
// Split the ConnectionString into segments so it doesn't make
// placeholder too wide.
string[] connectParts = GetConnectionString().Split(new char[] { ';' });
string connectString = " " + connectParts[0];
for (int i = 1; i < connectParts.Length; i++)
connectString += ";<br> " + connectParts[i].Trim();
return CreatePlaceHolderDesignTimeHtml(
"DataFile: " + DataFile + "<br />" +
"Connection string:<br />" + connectString);
}
' Generate design time markup.
Public Overrides Function GetDesignTimeHtml() As String
' Generate a design-time placeholder containing the
' DataFile and the ConnectionString properties.
' Split the ConnectionString into segments so it doesn't make
' placeholder too wide.
Dim connectParts() As String
connectParts = GetConnectionString().Split((";").ToCharArray())
Dim connectString As String
connectString = " " & connectParts(0)
Dim i As Integer
For i = 1 To connectParts.Length - 1
connectString &= ";<br> " & connectParts(i).Trim()
Next
Return CreatePlaceHolderDesignTimeHtml( _
"DataFile: " & DataFile & "<br />" & _
"Connection string:<br />" & connectString)
End Function
備註
方法 GetConnectionString 會將 DataFile 控件的 屬性對應至設計工具網站,然後使用 ConnectionString 控件的 屬性來產生連接字串。