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!

hi how do I go about setting up

Status
Not open for further replies.

ozpeppers

Programmer
Jul 17, 2001
32
BN
hi

how do I go about setting up, writing and executing an ado connecting to an access 97 database. The recordsourse being an sql statement used to populate a datalist?

Sounds simple and probably is.

Cheers in advance

Mark
 
p.s.

the sql statement should contain a varible that held in a text box?

again cheers
 
For Adodc1, in the properties window:

CommandType = 1 - adCmdText

Select ConnectionString and click the button that appears. Select the "Use connection string" option and click the build button. Browse to your database path and click the "Test Connection" button and make sure it succeeds. If not, it's a bad path or the drive the database is on is down (server?). Press Ok, then Apply on the origional form. Select the recordsourse tab, make sure the combo box says 1 - adCmdText, and type in your sql statement in the bottom textbox. That's hard coded, so if u need to change the sql statement at runtime, this is how I do it:

Const DBProvider as String = "Provider=Microsoft.Jet.
OLEDB.4.0;PersistSecurity Info=False"
Const DBPath as String = "C:\MyDatabasePath\MyDatabase.mdb"

dim strSQL as String
strSQL = "SELECT * FROM tblMyTable WHERE MyField = '" & txtCriteria.Text & "'"

Adodc1.Recordset.Close 'error here if already closed
Adodc1.Recordset.Open strSQL, DBProvider & DBPath

Set DataList1.DataSource = Adodc1

Hope that helps!

-Mike






DataSource=\\wcgoktulf153\tul1drftpln\MDB15sl\siteinfo.mdb; Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
Oops, messed up the connection string during copy/paste, here's what DBProvider should be, disregard the first statement after my name :)

Public Const DBProvider As String = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source="

Then u can concantinate the DBPath to the end of this to complete ur connection string, and the path is flexible. If u have to move the location, u only have to change ur constant and design time connnections.

-Mike
Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top