Solved

Passing parameters to ADODataSet

Posted on 2000-03-22
5
711 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
  • 2
  • 2
5 Comments
 

Expert Comment

by:Borrt
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
glad to hear that and thanks for the points graga

:o)
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now