Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Searching using Stored Procedures 1

Status
Not open for further replies.

kagee

Programmer
Apr 21, 2004
30
NL
i have a simple SELECT stored procedure (MS SQL Server)that takes in one parameter and returns values from a DB table

On executing the SP from the Database side, It works perfectly.

I got to load the results from the SP into a list box on mysearch form (DELPHI). i want to load the listbox value selected back to the main form.

How do i pass the results from the mysearch form back to the main form

STORED PROC CODE:
CREATE PROCEDURE CLIENTFINDER @selcname varchar (25)
AS
SELECT Clientname, Company, Title, Address, Town
FROM [portfolio].[dbo].[ADVCLIENT]
WHERE clientname LIKE @selcname + '%'
GO

DELPHI CODE:

procedure TFrmFindClient.BtnFindClick(Sender: TObject);
begin
//if u click the find button having entered text
with DModStocks.ADOSPFindClient do
begin
Close;
Parameters.ParamByName('@selcname').Value := EditFind.Text;
Open;
Active := True;

ShowMessage(Format('Number of records returned is %d', [RecordCount]));
// code to populate the list box once i get values from dataset
while not Eof do
begin
LBoxFind.Items.Add(Fields[0].AsString);
Next;
end;

end;
end;


Thanx :
Kagee
(Delphi beginner)
 
If you are asking how to communicate between forms, try treating the form as a class (which it is).

Add a property to the form class itself:
Code:
type
   TForm2 = class(TForm)
       ...    //   stuff that the IDE automatically puts in
   private
       function GetSelectedValue : String;
   public
       property SelectedValue : String read GetSelectedValue;
   end;

...

function TForm2.GetSelectedValue : String;
begin
   with LBoxFind do
   begin
       if ItemIndex <> -1 then
           Result := Items[ItemIndex]
       else
           Result := '';
   end;
end;


Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top