?
Solved

Problem to write in an Oracle Database

Posted on 2003-03-11
17
Medium Priority
?
260 Views
Last Modified: 2010-04-04
I am using Delphi 5 with an ODBC alias to access an Oracle database. I have no problem to read the informations in a table but the problem is when I want write a number and a name(by parameters), Delphi makes me a DBEngineError. Any ideas?
My Code :
QueryNouvelIntervenant.SQL.Text :=
  'INSERT INTO intervenant VALUES(' +':param_num'+ ',' +':param_nom' + ')';

QueryNouvelIntervenant.ParamByName('param_num').AsInteger := StrToInt(edt_num.Text);
QueryNouvelIntervenant.ParamByName('param_nom').AsString := Edt_nom.Text;
0
Comment
Question by:amidamaru
[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
  • 7
  • 5
  • 4
  • +1
17 Comments
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8110137
your text should be

 'INSERT INTO intervenant VALUES(:param_num,:param_nom)';


best would be also to qualify the correspondending fields
like

 'INSERT INTO intervenant (FieldName1, FieldName2) VALUES(:param_num,:param_nom)';

whereas fieldnameX must be replaced with your real fieldnames

meikl ;-)

0
 
LVL 1

Expert Comment

by:merry_prince
ID: 8110392
Would you please announce some detailed info? such as table structure, detailed error message, etc.
0
 
LVL 2

Expert Comment

by:IPCH
ID: 8110508
After setting parameters you must use QueryNouvelIntervenant.ExecSQL not QueryNouvelIntervenant.Open?

Ivan

P.S. I am only checking. :-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 8110534
nice check, ivan, and true ;-)
0
 

Author Comment

by:amidamaru
ID: 8117422
@kretzschmar : I also tested as you say but that does not change anything

@merry_prince :
Table intervenant :
Num NUMBER(9)
Nom VARCHAR2(20)

I try to translate from French
Error Message : The project AcceBd.exe makes an exception classes EDBEngineError with message 'Nonapplicable operation '.

@IPCH : I use a
QueryNouvelIntervenant.Prepare and after a
QueryNouvelIntervenant.ExecSQL
The exception come from the execsql

it is as if it did not accept the string from the parameter, when I write
'INSERT INTO intervenant VALUES(:param_num,''test'')';
he can write in the table without problems  
It's a nightmare
 
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8117640
well, ok,
you must define the paramtype of youe second
parameter to a stringtype, guessing the type
is currently unknown.

meikl ;-)
0
 

Author Comment

by:amidamaru
ID: 8117702
@kretzschmar :
    QueryNouvelIntervenant.SQL.Text :=
      'INSERT INTO intervenant VALUES (:param_num, :param_nom)';
QueryNouvelIntervenant.Params[0].DataType := ftInteger;
QueryNouvelIntervenant.Params[1].DataType := ftString;

I try this but no change always this ****** exception
it makes me crazy ^_^
0
 
LVL 1

Expert Comment

by:merry_prince
ID: 8117759
Can you use another param name instead of param_nom? Please try it.

If still mistake, would you please list the source codes related to database operations?
0
 

Author Comment

by:amidamaru
ID: 8117784
@kretzschmar :
    QueryNouvelIntervenant.SQL.Text :=
      'INSERT INTO intervenant VALUES (:param_num, :param_nom)';
QueryNouvelIntervenant.Params[0].DataType := ftInteger;
QueryNouvelIntervenant.Params[1].DataType := ftString;

I try this but no change always this ****** exception
it makes me crazy ^_^
0
 

Author Comment

by:amidamaru
ID: 8117810
Sorry i make a mistake and resend my old message oops !

procedure TForm1.FormCreate(Sender: TObject);
begin
    basename := 'BaseOracle';
    Database1.DatabaseName := basename;
    Database1.Open;

   //requête affichant tous les intervenants
    QueryAfficheIntervenants.DatabaseName := basename;
    QueryAfficheIntervenants.SQL.Text :=
      'SELECT num AS "Numéro",nom FROM intervenant ORDER
BY num';

    QueryNouvelIntervenant.DatabaseName := basename;
    QueryNouvelIntervenant.SQL.Text :=
      'INSERT INTO intervenant VALUES (:param_num, :p_nom)';
    QueryNouvelIntervenant.Params[0].DataType := ftInteger;
    QueryNouvelIntervenant.Params[1].DataType := ftString;

procedure TForm1.Bt_AjoutClick(Sender: TObject);
begin
  QueryNouvelIntervenant.ParamByName ('param_num').AsInteger := StrToInt(edt_num.Text);
  QueryNouvelIntervenant.ParamByName('p_nom').AsString :=  Edt_nom.Text;

  QueryNouvelIntervenant.Prepare;
  QueryNouvelIntervenant.ExecSQL;

  //this quey
  QueryAfficheIntervenants.Close;
  QueryAfficheIntervenants.Open;
0
 

Author Comment

by:amidamaru
ID: 8117943
Can it be possible that the driver odbc is not correct ?
I use Microsoft ODBC for Oracle
0
 
LVL 1

Expert Comment

by:merry_prince
ID: 8117994
Please create an ODBC db alias which driver is Oracle ODBC Driver. OK?
0
 

Author Comment

by:amidamaru
ID: 8118038
Wonderfull, it ok, thank you very much ^_^
But I don't understand why it does not work with the driver from microsoft ? It's not normal that they make driver and they don't work !!!
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 8118110
do you know any app from microsoft,
which works properly?

glad you got it work,
never gueesed that there is the problem.

merry_prince should be graded,
good work

meikl ;-)
0
 
LVL 1

Accepted Solution

by:
merry_prince earned 300 total points
ID: 8118135
If my memory isn't wrong. It maybe cause by the old ODBC driver type not support your oracle client program. Microsoft ODBC for Oracle only can support the version less than Oracle8.1.5. If want to support the version high than oracle 8.1.6, you should use Oracle ODBC Driver.

Just suggest you should format the code as below. It's benefit for reading.

procedure TForm1.FormCreate(Sender: TObject);
begin
   basename := 'BaseOracle';
   Database1.DatabaseName := basename;
   Database1.Open;

  //requjte affichant tous les intervenants
  with QueryAfficheIntervenants, SQL do begin
    DatabaseName := basename;
    Add('SELECT num AS "Numiro",nom FROM intervenant ORDER BY num');
  end; {with}

  with QueryNouvelIntervenant, SQL do begin
    DatabaseName := basename;
    Add('INSERT INTO intervenant VALUES (:param_num, :p_nom)');
  end; {with}

procedure TForm1.Bt_AjoutClick(Sender: TObject);
begin
  with QueryNouvelIntervenant do begin
    ParamByName ('param_num').AsInteger := StrToInt(edt_num.Text);
    ParamByName('p_nom').AsString :=  Edt_nom.Text;
    ExecSQL;
  end; {with}

 //this quey
  with QueryAfficheIntervenants do begin
    Close;
    Open;
  end; {with}
0
 
LVL 1

Expert Comment

by:merry_prince
ID: 8118928
If my memory isn't wrong. It maybe cause by the old ODBC driver type not support your oracle client program. Microsoft ODBC for Oracle only can support the version less than Oracle8.1.5. If want to support the version high than oracle 8.1.6, you should use Oracle ODBC Driver.

Just suggest you should format the code as below. It's benefit for reading.

procedure TForm1.FormCreate(Sender: TObject);
begin
   basename := 'BaseOracle';
   Database1.DatabaseName := basename;
   Database1.Open;

  //requjte affichant tous les intervenants
  with QueryAfficheIntervenants, SQL do begin
    DatabaseName := basename;
    Add('SELECT num AS "Numiro",nom FROM intervenant ORDER BY num');
  end; {with}

  with QueryNouvelIntervenant, SQL do begin
    DatabaseName := basename;
    Add('INSERT INTO intervenant VALUES (:param_num, :p_nom)');
  end; {with}

procedure TForm1.Bt_AjoutClick(Sender: TObject);
begin
  with QueryNouvelIntervenant do begin
    ParamByName ('param_num').AsInteger := StrToInt(edt_num.Text);
    ParamByName('p_nom').AsString :=  Edt_nom.Text;
    ExecSQL;
  end; {with}

 //this quey
  with QueryAfficheIntervenants do begin
    Close;
    Open;
  end; {with}
0
 

Author Comment

by:amidamaru
ID: 8134308
Thank you very much for answer so quickly ^_^
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month13 days, 8 hours left to enroll

800 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