Monday, March 12, 2012

why this works in query analyzer but not in code

I have this store procedure and I call it in the code and it returns nothing but when ran in QA it brings back all 4 employees. However it should only bring back two since two of the employees EmployeeID #'s are in the EmployeeEval table. Any ideas please -- I'm lost.
CREATE PROCEDURE dbo.sp_Employee_GetEmployeeLNameFNameEmpID
(
@dotnet.itags.org.facilityID nvarchar(2),
@dotnet.itags.org.companyID nvarchar(2),
@dotnet.itags.org.deptID nvarchar(20),
@dotnet.itags.org.Period int
)
AS
SELECT DISTINCT e.LastName + ',' + e.FirstName + ' - ' + e.EmployeeID AS ListBoxText, e.EmployeeID, e.LastName + ',' + e.FirstName AS FullName FROM Employee e LEFT JOIN EmployeeEval ev
ON e.CompanyID = ev.CompanyID AND e.FacilityID = ev.FacilityID
WHERE e.DeptID = @dotnet.itags.org.deptID AND e.FacilityID = @dotnet.itags.org.facilityID AND e.CompanyID = @dotnet.itags.org.companyID AND ev.PeriodID = @dotnet.itags.org.Period AND e.EmployeeID <> ev.EmployeeID
GOGot it to work here is my new SP in case anyone is interested.
CREATE PROCEDURE dbo.sp_Employee_GetEmployeeLNameFNameEmpID
(
@.facilityID nvarchar(2),
@.companyID nvarchar(2),
@.deptID nvarchar(20),
@.Period int
)
AS
SELECT e.LastName + ',' + e.FirstName + ' - ' + e.EmployeeID AS ListBoxText, e.EmployeeID, e.LastName + ',' + e.FirstName AS FullName FROM Employee e
WHERE e.DeptID = @.deptID AND e.FacilityID = @.facilityID AND e.CompanyID = @.companyID AND e.EmployeeID NOT IN (SELECT ev.EmployeeID FROM EmployeeEval ev
WHERE PeriodID= @. Period )
GO

I got my stored procedure working but now it won't bind anything to the ListBox even though QA is showing two results. Any ideas? Here is my code:

SqlConnection1.Open()

SqlCommand3.Parameters.Add(New SqlParameter("@.deptID", Session("deptID")))

SqlCommand3.Parameters.Add(New SqlParameter("@.Period", Session("Period")))

SqlCommand3.Parameters.Add(New SqlParameter("@.companyID", Session("companyID")))

SqlCommand3.Parameters.Add(New SqlParameter("@.facilityID", Session("facilityID")))

lbxEmployeeList.DataSource = SqlCommand3.ExecuteReader

lbxEmployeeList.DataTextField = "ListBoxText"

lbxEmployeeList.DataValueField = "EmployeeID"

lbxEmployeeList.DataBind()

SqlConnection1.Close()


Onewisehobbit,

First thing I would look at is to see if your session varables have been populated.

Regards

Chomps


I was thinking to complex -- thanks.

0 comments:

Post a Comment