Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need Help with BDE and TQuery

Status
Not open for further replies.

sanjna000

Programmer
Aug 1, 2003
132
GB
Hi,

I have a form with two edit boxes. They are mainly used to enter ID number and Description. When i enter values in the edit boxes and click on ok button it should insert newly added ID and Desc to the relevant table.

My Table structure is as follows:

ID : Number - Primary key
Desc: Alpha [100]

I created my database using Paradox.

The code i used is as follows:

Var
ID: Integer;
Desc: String;
qry: TQuery;

ID := StrToInt( Edit1.Text );
Desc := Edit2.Text
qry.Close;
qry.SQL.Clear;
qry.SQL.Add( 'INSERT INTO Table1 ("ID", "Desc") VALUES (ID, Desc)');
qry.ExecSQL;

But it doesn't seem to be working. Can any one help me out to solve my problem.

Thanks very much,
Sanjna.
 
Your code should look something like:
Code:
ID := StrToInt( Edit1.Text );
Desc := Edit2.Text
qry.Close;
qry.SQL.Clear;
qry.SQL.Add( 'INSERT INTO Table1 (ID, Desc)' );
qry.SQL.Add( ' VALUES (' + Edit1.Text + ',' + QuotedStr(Desc) + ')' );
qry.ExecSQL;
Alternatively, you can use Params where you have placeholders in the SQL statement for the variables. Check out the Delphi Help for Params in TQuery for further details.

Andrew
 
Hi Andrew,

Thank you so much for u r help. It works fine.

Sanjna...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top