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;
}
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
Paul Alexander
2009-04-10 06:24:28