[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

How to insert records to database

Posted on 2001-08-29
5
Medium Priority
?
234 Views
Last Modified: 2010-04-06
Hi, all Experts

I am using ADO to connect to MS Access database. I created the following codes to insert a record:

procedure TForm1.Button1Click(Sender: TObject);
begin
    with dm.ADOQuery1 do
    begin
        Active := false;
        SQL.Clear;
        SQL.Add('insert into category (description) values (''category1'')');
        Active := true;
    end;
end;

But when I run the program and click on button1, it shows some errors:
1. The operation requested by the application is not supported by the provider;
2. CommandText does not return a result set.

Please help me to fix it.

Thanks
0
Comment
Question by:jl2001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 6439149
it's interesting to note that you need to enclose strings in a single quote ' instead of a double quote " when using TADOQuery components with Access databases (dunno, never tried ADO with other databases, I usually use native access for other databases)

so let's say you want to insert something that the user has typed in an edit box, try this:

with ADOQuery1 do
begin
  Close;
  SQL.Text := Format('INSERT INTO category (description) VALUES (%s)', [QuotedStr(Edit1.Text)]);
  Open;
end;

using SQL.Text eliminates the need to call Clear and Add.



Hope that helped!
DragonSlayer.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6439382
do not open, do execute your query
0
 
LVL 44

Accepted Solution

by:
CrazyOne earned 200 total points
ID: 6439398
Here is what kretzschmar is referring to, change the Active := True to ExecSQL

procedure TForm1.Button1Click(Sender: TObject);
begin
   with dm.ADOQuery1 do
   begin
       Active := false;
       SQL.Clear;
       SQL.Add('insert into category (description) values (''category1'')');
       ExecSQL;
   end;
end;
0
 
LVL 6

Expert Comment

by:Jaymol
ID: 6439486
Actually, DragonSlayers comment will fix the first error message and Kretzschmar's comment will fix the second error.

John.
0
 

Author Comment

by:jl2001
ID: 6442695
Thanks all. ExecSQL is the best way to fix my problem.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question