Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

Working with TADO Table

delphi

  • Please log in to reply
1 reply to this topic

#1 MrDiaz

MrDiaz

    CC Resident

  • Just Joined
  • PipPipPipPip
  • 64 posts

Posted 03 July 2006 - 03:28 PM

The use of databases is becoming more and more popular each day. There is a lot of demand in this field and constantly there are thousand of customers looking for applications that use databases. Let me point out a few things before going into the code.

What are the benefits of working with TADOTable component and what can I do with it?

There are a lot of applications for this component, you can use microsoft access database and use the records of the database in your application. There are many uses for this, it can be for personal use, for let's say...create an agenda to store your personal notes. Maybe a catalog for your movie collection, music, etc...there are infinites uses that I cannot cover in just one tutorial.

What will this tutorial show me?

In this tutorial I am going to show you how you can connect to a database using TADO components. This TADOTable component is very useful, and easy to use. You will also learn how to display the results on fields and how to insert, edit, and delete information on your database.

How do I get started?

Let's stop the chit chat and get to the coding part. Well actually there's no need to code anything in this tutorial. What I am going to show you here is very simple, and it does not require actual programming. Ok let's get things going now.

First we are going to create our database using access in this case. Open Microsoft Access and insert as many fields as you want. You are free to choose your options. If you don't know where to start, create the same ones I did. That is:

Field Name Data Type
Name ----------------> Text
Last Name ---------> Text
Phone Number----> Number
Address -------------> Text
Email -----------------> Text
Website --------------> Text
Comments ----------> Memo

Once you have the database created then you just need to insert some data into it. You can do this either by doing it directly using Microsoft Access or using the software we will create. What I am going to do is insert only one data using Microsoft Access, so you can see how the information is displayed on your application and you don't get lost.

This is the record I have:

Name: Manuel
Last Name: Diaz
Phone: 999 999 999
Address: 2929 Street Whatever, Ontario
Email: admin@delphiaddicts.com
Website: http://www.delphiaddicts.com
Comments: This guy rocks!

So once we have our first record into the database then save the database as .mdb. Now let's go to Delphi and do what it needs to be done. First let's insert a TADOTable component. This component displays tables from databases. If you have more than one table, you need to insert more of course or use a TADOConnection. This component connects to a database and then you can read a table independently from the database. It is very helpful for large databases. In this case, we only have one database so we will only use one TADOTable to display our information.

Now we have to click our component (TADOTable) and look for the property ConnectionString.

- Click on the property and you will see 2 options.
- Choose the second one.
- Click Build.
- Select Microsoft Jet 4.0 OLE DB Provider
- Click Next
- Select the database to use.
- Test the connection if you want to make sure it works fine.
- Click Ok
- Click ok again.

Our connection has been set and it works perfectly fine. Our next step is looking for the table name to use, just click on the TADOTable component and look for the property TableName, then browse there and you will see the table name you created in access. Select it and that's about it.Now what we need to do is insert the components that are going to display the fields you created in Microsoft Access.

You can take a look of how mine looks, however you are free to choose your own way of display the information. Just make sure you use the components to work with databases. They are all into the palette Data Controls. I recommend you to use TDBEdit for the text and number fields and TDBMemo for the field "Comments".

Now we need a component to connect all our other components and we will be using TDataSource. This component can be found in the palette DataAccess. Once we insert the component into our form we need to set up the property DataSet and place our table there. Now one more component to get things going here, we need a component to navigate our records in the database. For this we will be using TDBNavigator, this component can be found in the palette Data Controls. Once we insert it into our form we need to set up the property DataSource and select DataSource1 (this will set up the connection with the database)

Now let's work with our components. You can do this indivually by choosing which component will be a specific field. To do this you just need to select a component and in the property that says DataSource browse and look for our DataSource1. Then we need to specify which field to use for each component, we need to look for the property DataField and choose there the data we will be using to display using that component. And then just do the same for each of your components.

And that's it! Just run the program and you can play around with your records, insert data, edit data, delete data. Whatever you do on Access you can now do it using your application. This is very useful because you can create a program to keep control of your own records. For example, I use stuffs similar to this to organize my movie collection, or my music library. There are no limits for what you can
using this components. Of course if you want to work with huge databases like for a company or something, it would be better using SQL instead. But that is an other story that I will be telling very soon.

Keep in touch and happy coding!
  • 0

#2 Guest_arslan220_*

Guest_arslan220_*
  • Guest

Posted 27 July 2009 - 02:16 AM

hi thanks for sharing.
  • 0





Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download