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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Access 2K Insert Format From Dephi

Status
Not open for further replies.

BillKilgore

Programmer
Mar 17, 2002
60
US
I've spent the last day and a half trying to insert some record values into an Access 2000 DB using Delphi 7. I've tried several variants of what you see below; with and without the 'QuotedStr,'with and without the '='
after VALUES, ADD and APPEND after SQL (INSERT, the most obvious, didn't work because an integer Index was required. The Table, BarStock, has no Index).
What I can find regarding SQL help in Delphi is somewhat sketchy. My research and recollection of SQL inserts shows this to be in the proper format.
I suspect that the problem results from my use of the ADO procedures where my own experiance is very limited.
My question, what is the proper format for an INSERT statement using ADO and is an ADOQ the proper device to use for an INSERT of strings and no Index?



adoqAppendBarStock.SQL.Add('INSERT INTO
BarStock (Symbol,Grade)
VALUES=' + QuotedStr(Bar.symbol)
+ QuotedStrBar.Grade));

(Note: In my program the code is in only one line.)

Any help, as always, is greatly appreciated.

Bill Kilgore

 
Your final query needs to be like this:


INSERT INTO BarStock (symbol, Grade) VALUES ('Somesymbol', 'SomeGrade')

your query is missing the values parens.

you will only need the quotedStr function if the values you are passing in are string/text fields, if it's a numeric field, then no quotedstr.

I have found the easiest way to troubleshoot queries is after creating the SQL and prior to opening it is:

ShowMessage(queryName.SQL.Text)

I would try:
Code:
SQL.Add('INSERT INTO BarStock(Symbol, Grade) VALUES ( ' + QuotedStr(Bar.symbol) + ', ' + QuotedStr(Bar.Grade) + ')');
what exactly are Bar.Symbol and Bar.Grade? Other fields in a different table? variables?



Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases: The Fundamentals of Relational Database Design
 
Thank you Lespaul for the timely response and for the database reference which I've downloaded. The devil is indeed in the details.

The "bar.symbol" is a Delphi record refering to the type of metal the bar contains, for instance iron or bronze, while "bar.grade" refers to its basic metallurgy as in 1040 for low-carbon steel. There are records for bar, sheet, tube, tool, and extrusion to name a few.

Anyway, thanks again,

Bill Kilgore
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top