Delphi and Access!

Conect a Delphi form with an access table!

Page 1 of 1

2 Replies - 1481 Views - Last Post: 28 September 2010 - 03:09 PM Rate Topic: -----

#1 Guest_NIck*


Delphi and Access!

Posted 28 September 2010 - 10:09 AM

Hello I am trying to connect an access table with a form in delphi can someone help I have succesfully connected delphi with access but I have a form and I want to type in it a name and give me in other fields of my form the rest that my access table contains.
Example I have a table cusromer(Which has phone ,name, age)My key is the name so I want to enter in my delphi form the name and complete the rest of the form like this.
Can it be done?

Is This A Good Question/Topic? 0

Replies To: Delphi and Access!

#2 Guest_Guest*


Re: Delphi and Access!

Posted 28 September 2010 - 10:11 AM

The form will be empty In the begging I want to enter only the name and the rest should be completed by the code i delphi but how?I am new in this so I am try by queries ,I have delphi 7
Was This Post Helpful? 0

#3 Ionut   User is offline

  • D.I.C Lover
  • member icon

Reputation: 386
  • View blog
  • Posts: 1,057
  • Joined: 17-July 10

Re: Delphi and Access!

Posted 28 September 2010 - 03:09 PM

Of course it can be done and you have three ways to achive this:
1. put some textboxes on your form, put an ADOConnection, ADOQuery. In sql property of ADOquery, put
INSERT INTO table VALUES (@param1, @param2, @param3) //just an example, give meaningfull names to your parameters 

Then on your submit button, add
With adoquery1 do begin
   Parameters.ParamByName('param1').Value := edit1.text; //value is variant so you don't need to do conversions, but pay attention to column's data type and do the correct assignment
   Parameters.ParamByName('param2').Value := edit2.text;
   Parameters.ParamByName('param3').Value := edit3.text;

2. in sql property, write
SELECT * from table

and in code
With adoquery1 do begin
   if Active then Close;
   FieldByName('Name').AsString := edit1.text;
   FieldByName('Age').asInteger := StrToInt(edit2.text);
   FieldByName('Telephone').asString := edit3.text;

3. use dbEdit controls (Data controls tab)
Here you have to add a datasource. Assign to DataSet property of DataSource adoQuery, add to DataSource property of dbEdit the DataSource(by default would be DataSource1). Into dataField property of dbEdit put the name of the column you ant to assign(name for example). When you create the form, be sure you open the dataset(adoquery1) and you put it in insert mode. On submit button, all you have to do is to post the changes(as in the second example)

This pieces of information should give you a point to start.

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1