Question Converting VB6 ADODB to ADO.NET

TBossAZ

Active member
Joined
Mar 31, 2009
Messages
43
Programming Experience
5-10
Hello everyone,

I am working on a project that involves converting some "legacy" VB6 code to .NET. Part of the project involves having a user select a DSN from a list box, to export some data to the selected data source.

I have the following VB6 code:

VB.NET:
Set TempDB = New ADODB.Connection
TempDB.Properties("Prompt") = adPromptComplete
TempDB.Open "DSN=" & DSN_NAME

What would be the .NET equivalent to the above code, especially for Line #2?

I do know that you can reference a .dll and import the ADODB namespace, but I wanted to find out if there was another way to do this.

Any questions or suggestions would be appreciated.

Thanks!
 
The DSN will cite a connection string, which you can take and use with a DbConnection (note, concrete subclasses of this exist such as OracleConnection, SqlConnection)
 
Does anybody have any other ideas or suggestions. The old VB6 code would prompt the user for username and password, or for a file name depending on the type of datasource. I am sure it had something to do with this line:

VB.NET:
TempDB.Properties("Prompt") = adPromptComplete

Anybody done anything like this in .NET
 
With the help of a friend and some research on the Internet, I have found a solution to my issue with converting the old VB6 code to something that will work in .NET.

I do not thing there is anythingin the .NET language that would replace the lines of code that was giving me trouble, but there was something that could be done to make the VB6 code run in the .NET environment (did that make sense?).

What I found out was that you can add a reference to the Microsoft ActiveX Data Objects 2.7 Library (a COM Reference), which will expose the ADODB Namespace, and then make just minor changes to the code:

Old VB6 Code:
VB.NET:
Set TempDB = New ADODB.Connection
TempDB.Properties("Prompt") = adPromptComplete

.NET Code with ADODB Namespace:
VB.NET:
Dim TempDB As New ADODB.Connection
TempDB.Properties("Prompt").Value = ADODB.ConnectPromptEnum.adPromptComplete

Hope this will help other people in the future
 
Back
Top