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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO connection string with variables

Status
Not open for further replies.

impulse24

IS-IT--Management
Jul 13, 2001
167
US
Hello,

I am creating a program to loop through db's in a directory. I have a variable for the database name. How do I use this variable in the following connection string:

connectstring = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Programming Tests\ & strDbName;" _
& "Persist Security Info=False"

strDbName contains the database name. I know I have to surround the variable with quotes or something, but can't get it to work. Can someone please show me the syntax. Thanks
 
Hi,

You need to have the variable outside the "
like this:
connectstring = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Programming Tests\" & strDbName & _
& "Persist Security Info=False"

Sunaj


 
Sunaj is correct, except you will need the semi colon after the variable


connectstring = "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=C:\Programming Tests\" & strDbName & _
& ";Persist Security Info=False"

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top