我有一个从Sql返回LoginStatus的方法。存储过程是最底层的问题。
在运行时,我只能从DataSet获取[2]的列。行计数始终为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;
}
使用的存储过程:
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
答案 0 :(得分:0)
试试这个
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