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

Connection paths with DB

Status
Not open for further replies.

barbs2

Technical User
Jan 24, 2003
8
IE
Is there any way to make connection paths in the vb Ado control generic?
From example hardcoded can look something like below:

Data Source=" & App.Path & "\db.mdb

Can you do something that will have the same effect on the ado?
 
Surely yes. ADO control is as easy as Data one. You must initialize path to your data file:

adcMyData.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & App.Path & "db.mdb;"
adcMyData.Refresh
 
When I do this I get an error saying "data source name not found and no default driver specified"?
 
1.Make sure that Jet 4.0 is installed on your machine(check MDAC version)

2.Sorry I missed slash in previous post. There should have been "\db.mdb", not "db.mdb". App.Path is sometimes VB install path so check it under debugger ...

4.Specify record source and type of command ADO control must execute against your Access database, for example:

adcMyData.RecordSource = "MyNiceTable" ' here must be you real table name
adcMyData.CommandType = adCmdTable
adcMyData.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  "Data Source=" & App.Path & "\db.mdb;"
adcMyData.Refresh

I've tried that code and no errors have occurred.
 
Cool that worked, cheers. Sorry to be a pain but using this method how do I link a database field to a text box. For eg using the vb properties box of the textbox you select the ado control in the data source box and the data field property in the data field?
 
You can do it like that or you can set it with code:

Text1.DataSource = Nothing
Text1.DataMember = Nothing

Text1.DataSource = ado
Text1.DataMember = rs!fieldname

Nunina
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top