[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 757
  • Last Modified:

Passing parameters to ADODataSet

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
graga
Asked:
graga
  • 2
  • 2
1 Solution
 
BorrtCommented:
ummmm im only new to delphi but have you tried resetting the variable before you run through the second time ?????
0
 
BorrtCommented:
ummmm im only new to delphi but have you tried resetting the variable before you run through the second time ?????
0
 
EpsylonCommented:
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
 
gragaAuthor Commented:
Epsylon,

Thanx again.
I just had to insert:

ADODataSet1.Parameters.Refresh

before your code and everything is working fine now.

0
 
EpsylonCommented:
glad to hear that and thanks for the points graga

:o)
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now