如何检索从sql storedprocedure返回的单个值?

时间:2016-02-11 06:16:37

标签: c# sql stored-procedures dataset

我想查看员工的最后一条记录,发现它是输入记录或 退出记录。我有一个存储过程,返回单个值(true / false)。 这是我的代码:

PROCEDURE [dbo].[SP_FindLastEnterExit]
@EmpID int = 0,
@recDate Date
AS
Begin
    return(Select top 1 EnterOrExit From tblDailyTimes 
where EmpID = @EmpID and recDate = @recDate Order By recDate , recTime Desc)

End

如何在我的Windows应用程序中使用此值?

我尝试了下面的代码,但它返回' -1'

private void CheckForEnterOrExit()
    {
        try
        {


            EmployeeDB3DataSetTableAdapters.tblDailyTimesTableAdapter ta = 
new EmployeeDB3DataSetTableAdapters.tblDailyTimesTableAdapter();
                DataRow dr = ((DataRowView)tblEmployeesBindingSource.Current).Row;
                int id = (int)dr.ItemArray[0];
                DateTime dt = new FunctionsClass().milady(txtShamsrDate1.Text);
                int r = (int)ta.SP_FindLastEnterExit(id, dt);
                int e = Convert.ToInt32(tblDailyTimesTableAdapter1.SP_FindLastEnterExit(id, dt));
                rbtnEnter.Checked = Convert.ToBoolean(e);
                rbtnExit.Checked = !rbtnEnter.Checked;
        }
        catch
        {

        }
        finally
        {

        }
    }

1 个答案:

答案 0 :(得分:1)

尝试为storedprocedure声明一个out参数,并在代码中使用该参数来检查值。