Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

connect to ODBC from VB

Status
Not open for further replies.

myasin78

Programmer
Jan 26, 2004
50
US
I am currently working on VB6.0 application that uses MS Jet to connect to Access DB. I need to be modify the code in order to make it talk to ODBC DB in stead, could someone send me a sample code please.
this is the current code that i have to modify.

Public Function GetDBConn() As String
Dim buffer As String
buffer = "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = "
buffer = buffer + gNetFromPath + "AutoWeighData2.mdb;"
GetDBConn = buffer

End Function

I thank you all in advance.
 
If the computer has a system DSN setup correctly (call it 'MyDSN') then all you need is the following,

Code:
Public Function GetDBConn() As String
Dim buffer As String
buffer = "DSN=MyDSN"
GetDBConn = buffer
    
End Function


Take Care,

zemp

"If the grass looks greener... it's probably because there is more manure."
 
I will let you know when i get it to work, thanks again.

myasin
 
I mave have steered you wrong. I falsely assumed you were using ADO. If you are not then the information I gave you may not be at all helpful.

Take Care,

zemp

"If the grass looks greener... it's probably because there is more manure."
 
I am a perl,tcl/tk,c++,html,sql programmer not very good with VB.
I just had to modify a projec that someone else wrote.

could you tell me how would i found out what I am using exactly.

thanks.
 
will this indicate that I am using ADO?

Dim cnn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rst As New ADODB.Recordset
 
You can check the project references. In the IDE go to the 'project' menu and select 'references' (near the bottom) and see which data objects you are using. If you see something like 'Microsoft ActiveX Data Objects...' then you are using ADO.

You can also check the variable declarations, if it says 'ADODB...' then you are using ADO.

Other wise post the code where that connection is opened and we can probably tell you which you are using.

Take Care,

zemp

"If the grass looks greener... it's probably because there is more manure."
 
I am using ADO, so i will test you code sortly.
thanks alot.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top