Click to See Complete Forum and Search --> : How to call a stored procedure in VB?


muralirajan
August 11th, 1999, 07:07 AM
I will be grateful to you if you please send me the answers.

I have a Employee table which has EmpID, Name & salary. I have a stored procedure which passes EmpID and returns the EmpName.

The syntax for creating the stored procedure is like this,

Create Procedure pr_IDInNameOut (@TempID varchar(2), @TempName varchar(15) OUTPUT)
as
select @TempName = EmpName from EmpMaster
where EmpIDl = @TempID
RETURN

Now, to execute the stored procedure with passing EmpId & to get EmpName the code is like this,

declare @ResName varchar(15)
execute pr_IDInNameOut 01, @ResName OUTPUT
select @ResName "Employee Name"

The above code works well in SQL server.
The problem is, I want to enter the EmpId in a text box of my VB form and the resulting EmpName to be displayed in a label of my VB form. WHAT IS THE REQUIRED CODE?

Secondly and most importantly, I want to display the list of the Employees in a db grid control, who are getting salary greater than the value entered in the text box.
Is it possible?. If possible what is the code for the same?


muralirajan

Lothar Haensler
August 11th, 1999, 07:14 AM
the easist way to do what you want is:
- use VB 6
- create a Data project - this will add a data environment designer to your project
- in the data environment designer add a new command (or Insert Stored Procedure).
DED will then automatically find out all information about the parameters.
- in your code write

dim strName as string
dataenvironment1.pr_IDInNameOut 1, strName



strName should then contain the name.

As for the dbgrid I'd use an ADC control and bind the DBGrid to the aDC control. No coding required!