Solved

Passing parameters to ADODataSet

Posted on 2000-03-22
5
724 Views
Last Modified: 2012-06-27
I have a problem to retrieve the record from ADODataSet by changing its parameters:

Scenario:

ADODataSet of CommandType cmdStoredProc is connected to Access2000 query.
Query is a simple:
SELECT * FROM CLIENT WHERE CODE = [:INVALUE]

I open the query with:

with qryClient do begin
  Close;
  Parameters.Items[0].Value := sCode;
  Open;
  end;

When I assign value to the Parameters[0] of the dataset, everything works correct for the first time. However every subsequent assigning of parameter value does not locate the correct record.

i.e.
Calling for the first time with Code='A' the query retrieves 'Client A'
Calling next time with code='B' will still return 'Client A'

I realise that using 'locate' or 'filter' on full client query would be a solution, but in my case qryClient is required to hold only one record

0
Comment
Question by:graga
[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
  • 2
  • 2
5 Comments
 

Expert Comment

by:Borrt
ID: 2647288
ummmm im only new to delphi but have you tried resetting the variable before you run through the second time ?????
0
 

Expert Comment

by:Borrt
ID: 2647291
ummmm im only new to delphi but have you tried resetting the variable before you run through the second time ?????
0
 
LVL 13

Accepted Solution

by:
Epsylon earned 100 total points
ID: 2647297
I think you are handling the parameters wrong.

Adding a parameter:

var p: TParameter;

  p := ADODataSet1.Parameters.AddParameter;
  p.Name := 'INVALUE';
  p.Value := sCode;


Changing a parameter:

  ADODataSet1.Parameters.FindParam('INVALUE').Value := sCode;
0
 

Author Comment

by:graga
ID: 2647338
Epsylon,

Thanx again.
I just had to insert:

ADODataSet1.Parameters.Refresh

before your code and everything is working fine now.

0
 
LVL 13

Expert Comment

by:Epsylon
ID: 2647354
glad to hear that and thanks for the points graga

:o)
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

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 80
creating threads in delphi 1 166
PHP preg_replace code convert to Delphi 14 82
Is there any way to treat Lock record in table with clientdataset? 3 32
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…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

726 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