问题描述
我想知道我怎么可以添加数据链接的形式给我的Windows应用程序。你知道那些表格,用户可以在女巫的SQL服务器上的选择,他们将要连接他们要去什么类型的安全使用及西隧的数据库。
I am wondering how I can add DATA LINK form to my WIN application.You know those forms where Users can choose on witch SQL server they going to connectand what type of security they going to use and on wht database.
这样的事情在这幅画
Something like on this picture
推荐答案
您可以做到这一点通过一些COM Introp ......但你必须要拉了一堆互操作程序集到您的项目,可以是一个拖累。这code将使用反射,而不是显示对话框。
You can do it through some COM Introp...but then you have to pull in a bunch of Interop assemblies into your project which can be a drag. This code will show the dialog using reflection instead.
public static string ShowDialog( IWin32Window owner,
string connectionString )
{
Type dlType = Type.GetTypeFromProgID( "DataLinks", true );
Type acType = Type.GetTypeFromProgID( "ADODB.Connection", true );
object form = Activator.CreateInstance( dlType );
object connection = Activator.CreateInstance( acType );
acType.InvokeMember(
"ConnectionString",
BindingFlags.Public | BindingFlags.SetProperty,
null,
connection,
new object[]{ connectionString }
);
object result =
dlType.InvokeMember(
"PromptEdit",
BindingFlags.Public | BindingFlags.InvokeMethod,
null,
form,
new object[]{ connection }
);
if( result != null && (bool)result )
return acType.InvokeMember(
"ConnectionString",
BindingFlags.Public | BindingFlags.GetProperty,
null,
connection,
new object[]{} ) as string;
return null;
}
这基本上转化为下面的VB脚本
This basically translates to the following VB Script
form = GetObject( "DataLinks" )
connection = GetOBject( "ADODB.Connection" )
connection.ConnectionString = "existing connection"
form.PromptEdit( connection )
Return connection.ConnectionString
这篇关于在.NET C#SqlConnectionStringBuilder形式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!