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 控件的 属性生成连接字符串。