Solved

Passing parameters to ADODataSet

Posted on 2000-03-22
5
729 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

696 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