Doug,
First, set two references in your project (under COM):
Microsoft OLE DB Service Component 1.0 Type Library
Microsoft ActiveX Data Objects 2.7 Library
The ADO reference can be to any version that you wish.
Once you do that, the following code will prompt for a new connection:
// The data links component.
MSDASC.DataLinks pobjDataLinks = null;
// A connection class instance.
ADODB._Connection pobjConnection = null;
// Create the data links component. Wrap in
// a try/finally block to release when done.
try
{
// Create the data links instance.
pobjDataLinks = new MSDASC.DataLinksClass();
// Set the window handle.
// This assumes you are doing this in a control, and have a parent
window handle to use.
pobjDataLinks.hWnd = (int) this.Handle;
// Get the new connection.
pobjConnection = (ADODB._Connection) pobjDataLinks.PromptNew();
// From here, you can get the ConnectionString property and do what you
will with it.
}
finally
{
// Release the data links class if it is not null.
if (pobjDataLinks != null)
// Release.
Marshal.ReleaseComObject(pobjDataLinks);
// Release the connection if it exists.
if (pobjConnection != null)
// Release.
Marshal.ReleaseComObject(pobjConnection);
}
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Doug" <dk*******@hotmail.com> wrote in message
news:%2****************@tk2msftngp13.phx.gbl...
Hi,
I was wondering if someone can help me - I need to provide the user with
the DataLinks dialog box and then use the connection string that is generated
from it. I've tried, but can't figure it out. I was hoping someone could
provide me a C# example? Thanks in advance.
Doug