I have a method that returns LoginStatus from Sql. The Stored procedure is at bottom of question.
On running, I am only able to get Column at [2] from DataSet. Row Count is always 0.
DataSet logStatusDs = new DataSet();
protected void Page_Load(object sender, EventArgs e)
{
GetLoginStatus(Convert.ToInt32(Session["userid"]));
string aa = logStatusDs.Tables[2].Rows.Count.ToString();
// if (aa == "In")
// {
// btnCheckout.Visible = true;
// }
//else
// {
// btnCheckIn.Visible = true;
// }
}
public DataSet GetLoginStatus(Int32 userId)
{
//DataSet logStatusDs = new DataSet();
//load the List one time to be used thru out the intire application
var ConnString = System.Configuration.ConfigurationManager.ConnectionStrings["EMSJConnectionString"].ConnectionString;
using (SqlConnection connStr = new SqlConnection(ConnString))
{
using (SqlCommand cmd = new SqlCommand("get_LoginStatusQ", connStr))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@UserId", Session["userid"]);
cmd.Connection.Open();
new SqlDataAdapter(cmd).Fill(logStatusDs);
}
}
return logStatusDs;
}
Stored Procedure Used:
alter PROCEDURE [dbo].[get_LoginStatusQ]
@UserId int
AS
BEGIN
SET NOCOUNT ON;
SELECT TOP 1 UserTimeId, LoginStatus
FROM UserTime
WHERE UserId = 2
ORDER BY UserTimeId DESC
END
Try this
alter PROCEDURE [dbo].[get_LoginStatusQ]
@UserId int
AS
BEGIN
SET NOCOUNT ON;
SELECT TOP 1 UserTimeId, LoginStatus
FROM UserTime
WHERE UserId = @UserId
ORDER BY UserTimeId DESC
END