Solved

Passing parameters to ADODataSet

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

828 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