Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1779
  • Last Modified:

databases ......

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
joyrider
Asked:
joyrider
  • 4
  • 3
  • 2
  • +1
1 Solution
 
MarcGCommented:
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
 
MarcGCommented:
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
 
Mohammed NasmanSoftware DeveloperCommented:
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
joyriderAuthor Commented:
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
 
joyriderAuthor Commented:
ow yeah forgot to say i also setted the datafield value to customer name in the dblistbox
0
 
joyriderAuthor Commented:
ow yeah forgot to say i also setted the datafield value to customer name in the dblistbox
0
 
Stuart_JohnsonCommented:
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
 
MarcGCommented:
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
 
joyriderAuthor Commented:
ah ok hehe thought it would do it automaticly :)

thanks u also helped me with question 1 so u get the points :)
0
 
Stuart_JohnsonCommented:
That's why you use the DBLookupListBox or DBLookupComboBox!  It does the adding for you automatically!

0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now