Very simple connection to an Access 2000 database using ADO (Views: 2141)
Problem/Question/Abstract: How can I connect my Application to an Access 2000 Database Answer: You have an access 2000 Database with a few table and are not very familiar with ADO. You want to, at least, connect you database to your application (For example one of your friend don't have an access viewer and you want him to be able to read you Tip and Trick DataBase). Here how it work. First put a TADOConnection Component on your form. Open the object inspector and search for the connection string property. Click the 3 dot icon (...). You should see a windows with the following title bar: Form1.ADOConnection1 Connection String As it's our first connection ever we gonna use a connection string as connection Source. Click the second radio button. Don't type anything in the textbox, just click the build button to automate the process. Another windows appear named Data Link Properties. There 4 sections called Provider, Connection, Advanced ans All. Go in provider. As I don't want to go in detail and let you make a quick connection I recommend you chose the latest Microsoft Jet OLE Provider. On my version it's 4.0, if you don't have updated yet your sustem it will be 3.51. Click Next. You are now in the connection section. Click the 3 dot (...) to access your database with the open dialog. Ok following you are not a DataBase expert and don't share it with other users you don't need any login name / password, so delete the Admin default username. We don't need to edit the Advanced and All section. Leaves that blank and click ok, click ok another time. Back to the form. Open the object inspector. First set the LoginPrompt to false. Got to the connected property, make it true. You are connected! Wanna be sure? Yes, all was done non visual. We will put some visual components on the form but first we need to complete the non visual part. Add a TADODataSet to the form. Go to the Connection propery, click down and choose ADOConnection1. In CommandType click cmdTableDirect, we don't need any fancy thing, let's get straight to the point. In the command text property click down and select the main table of you app (I assume for this article that you have only one table). In the active property click true. The rest go a lot like BDE application. Go to the DataAccess category and put a TDataSource component on the form. Put it's DataSet property to ADODataSet1. We're ready for a visual component. Now put a TDBGrid on the form. In the DataSource property choose DataSource1. That's it your connected! |