Solved

databases ......

Posted on 2001-08-29
10
1,770 Views
Last Modified: 2012-08-13
Hi,

I had created a database in access for customers to look some goods up of ours now we were going to buy the runtime's for access but this was way to expensive so i decided to give it a shot with delphi. I never tried databases using delphi But i managed to get something running. I used a dbgird,adotable & datasource compentent and i got one of the tables from my ms access mdb file in the grid.

I noticed some things :
in the mdb file i have several tables linked to each other (relations) but when i look at the dbgrid i only see the id's instead of what this id is represented by in another table so my question is how can i get the grid to show not the id but the name of what the id is (so it should be looked up in another table).

Another question is
how do the DBlistboxes & DBcomboboxes work ? i never could get em running, in access i had a form wich i want to remake in delphi that showed 3 listboxes each wich showed data from a table how can do this in delphi ?? i nvr could get it working (so example source code is appreciated)

also i'm looking for sites that explains this, in particular with mdb (access) files

thanks !
0
Comment
Question by:joyrider
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 3

Expert Comment

by:MarcG
ID: 6438507
for joining tables you need a Query component and SQL.
If you have 2 tables and they are connected with an ID, lets say table 1 contains customer name and id and table 2 contains the customer address and id, you would join with a query connect a data source to the query and connect for example a dbGrid to the database.
The SQL string would look like this
'SELECT * FROM Table1, Table2 WHERE ID1 = ID2'
0
 
LVL 3

Expert Comment

by:MarcG
ID: 6438512
and if you have a datasource that is connected to your data and then set it as datasource for you dbcombobox it should be filled with the data automatically.
0
 
LVL 22

Expert Comment

by:mnasman
ID: 6438521
Hello

  you can do that using lookupfield

and here's free database course for delphi with access

Delphi Database Programming Course
http://delphi.about.com/library/weekly/aa010101a.htm

Best regards
Mohammed Nasman
0
 

Author Comment

by:joyrider
ID: 6438734
mnasman i already looked at that site all day & it has gotten me nowhere :( marcG thanks i got the 1st question now but i still can't get the listbox to work !!

what am i doing wrong ?
i putted a Adoqeurry datasource & dblistbox on the form
in adqeurry i made a simple querry (select customername from tblcustomers) and entered the connection string
in datasource i had set the dataset to the adoquery and in the dblistbox i had set the datasource to datasource1

after this was done i setted the active value of the adoquerry to true & ran the program all i got was an empty listbox (yes the querry returns results cause i tested it with a dbgrid)

any idea's ?
0
 

Author Comment

by:joyrider
ID: 6438741
ow yeah forgot to say i also setted the datafield value to customer name in the dblistbox
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:joyrider
ID: 6438753
ow yeah forgot to say i also setted the datafield value to customer name in the dblistbox
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6439090
Hi joyrider,

I don't know if this is still applicable or not, but a few years ago, the company I was working for wrote an app in Delphi which used Access as it's DB.  After completing the app, my R&D "Manager" discovered that we could not distribute the application legally without having either VB or Access installed on the clients PC (or obtain a license to legally install the drivers onto their PC).  This was a real pain.  What we had to do was ship a copy of Access 97 with our app to comply with the license.

I would strongly suggest you find out if this still applies, and if it does, perhaps you should look at a different DB - such as Interbase (which is better than Access anyway).

With your question about the listboxes and comboboxes, try this:

Drop a TDatabase component onto the form (or TADOConnection).  Connect it to your Access database.  Drop a TTable (or TADOTable) onto the form and link it to the TDatabase (or TADOConnection depending on the way you went).  Next, drop a TDatasource component onto the form and link it to your Table component.

Next, drop a TDBLookupComboBox onto the form.  Set it's ListSource property to the TDataset.  Choose a table from the ListField and KeyField properties and away you go.  The same applies for a TDBLookupListBox.  It had me fooled for ages too :)

Cheers!

Stu.
0
 
LVL 3

Accepted Solution

by:
MarcG earned 50 total points
ID: 6439516
just read this example in Delphi help on DBListBox
"
while not Table2.Eof do begin

  DBListBox1.Items.Add(Table2.FieldByName('Country').AsString);

  Table2.Next;

end;"

It seems to me you have to fill the box 'manually'.
0
 

Author Comment

by:joyrider
ID: 6439926
ah ok hehe thought it would do it automaticly :)

thanks u also helped me with question 1 so u get the points :)
0
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6440047
That's why you use the DBLookupListBox or DBLookupComboBox!  It does the adding for you automatically!

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now