Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-19-2007, 06:07 PM
Tavares Tavares is offline
Senior Member
 
Join Date: Feb 2001
Posts: 1,318
Default Database Question.Please Help me!!

Hi!

I would like to have a little explanation on this database scenario here.

Lets say I have two tables on my database: Customers and Orders.

Customers
CustomerID Integer AutoIncrement
Name Varchar 50
Address Varchar 60
Phone Varchar 15

Orders
orderID INteger AutoIncrement
Product varchar 50
cust_ID Integer

This is my database.

On Delphi I have a sqlConnection,a sqlDataSet, a DataSetProvider and a ClientDataSet. IF I put this sql statement inside the sqldataset commandtext property :

SELECT * FROM CUSTOMERS C,ORDERS O

If I use a ClientDataSet and try to assign a value to all fields from both tables will IT be possible?

ClientDataSet.append;
ClientDataSet1.fieldbyName('Name').asString := edtName.Text;
ClientDataSet1.fieldbyName('PHONE').asString := edtPhone.Text;
ClientDataSet1.fieldbyName(PRODUCT').asString := edtProduct.Text; // field from orders table
ClientDataSet.Post;
ClientDataSet.ApplyUpdates(0);

Can I do that or I have to have 2 ClientDataSet one for Customer and another for orders?





Thank You!
Eduardo Tavares
[link=http://www.eduardotavares.com.br]www.EduardoTavares.com.br[/link]


Plz accept if it helps.I always do.
"Daddy,what does Formatting C:... mean?"
---------------------------------------------
Borland Delphi 2006
Reply With Quote
  #2  
Old 04-19-2007, 10:11 PM
Eddy-B Eddy-B is offline
Senior Member
 
Join Date: Feb 2002
Posts: 1,467
Default RE: Database Question.Please Help me!!

Personally, i rather work with queries; they give me more direct control over what i do. And i know it is impossible to insert records into 2 tables at the same time. I assume a TTable.Insert cannot do it either.

[DELPHI]Q:=TQuery.Create;
Q.SQL.Add('INSERT INTO .....');
Q.ExecSQL;[/DELPHI]

Eddy-B

Please click Accept as answer if this helped
Reply With Quote
  #3  
Old 04-20-2007, 04:08 AM
daltamira daltamira is offline
Senior Member
 
Join Date: Aug 2006
Location: Argentina
Posts: 959
Default RE: Database Question.Please Help me!!

You must to have two ClientDataSets, one for Customers and another for Orders. But, if you use SQLConnection, let me suggest you that you use SimpleDataSets instead of ClientDataSets.
Reply With Quote
  #4  
Old 04-20-2007, 07:10 AM
GerardAtJob GerardAtJob is offline
Member
 
Join Date: Apr 2007
Posts: 84
Default RE: Database Question.Please Help me!!

only my 2 cent... lol

Only : SELECT * FROM CUSTOMERS C,ORDERS O ???

Should be more like :
SELECT *
FROM CUSTOMERS C,ORDERS O
WHERE C.CustomerID = O.cust_ID; // <<----

!@%#... I got too long without playing with databases... can't answer exactly lol sry

anyway ... have fun
Reply With Quote
  #5  
Old 04-21-2007, 11:02 PM
digitiger digitiger is offline
Senior Member
 
Join Date: Jan 2001
Posts: 716
Default RE: Database Question.Please Help me!!

First, as suggested in previous answere, you must have some criteria for joining two tables and one way is to specify some condition , just as shown in previous example.

Next, comming back to you original question, shortest answere is that "No, it is not possible"

but there are very easy alternatives

say you still need to show the records as per your command text in one single db grid and also want to enable data updates on same. In this condition you will have can display the results in the grid but for updating you can use related single value controls (TEdit, TCheckbox, TDateTimePicker etc) perhaps above the grid.

then in OnScroll event of your dataset (connected to grid through datasource), you can read and update the related values in the single value controls.

Also instead of using normal tdbnavigator it might be easier for you to use simple button etc and in each one of them you can put the related commands like dataset.next, dataset.previous etc.

Also in save/delete/insert button you can put the related logic to update the values back to table(s). and here lies the actual hack. In the background, you will be using three datasets, two for value updations based on input in the single value controls, and third one to be connected to grid etc for display purpose (remember to re-open the this third dataset after every save operation on any of the first two datasets.


Hope it is of some help and if it does then you may accept the answere
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 08:12 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.