标题:[转载] 精确统计在线人数
取消只看楼主
liuminghui
Rank: 6Rank: 6
等 级:贵宾
威 望:20
帖 子:2882
专家分:0
注 册:2007-1-26
 问题点数:0 回复次数:0 
[转载] 精确统计在线人数

[转载]
private void Page_Load(object sender, System.EventArgs e)
{
if (Application["online"] == null)
{
DataTable dtnew = new DataTable();
dtnew.Columns.Add("userid",typeof(string));
dtnew.Columns.Add("lastaccesstime",typeof(DateTime));
Application["online"] = dtnew;
}

DataTable dt = Application["online"] as DataTable;
DataRow[] rows = dt.Select("userid='"+Session.SessionID+"'");
if (rows.Length == 1)
{
DataRow dr = rows[0];
dr["lastaccesstime"] = DateTime.Now;[转载]

}
else
{
DataRow dr = dt.NewRow();
dr["userid"] = Session.SessionID;
dr["lastaccesstime"] = DateTime.Now;
dt.Rows.Add(dr);
}
for(int i = 0 ; i < dt.Rows.Count; i++)
{
DataRow dr = dt.Rows[i];
TimeSpan t = DateTime.Now - Convert.ToDateTime(dr["lastaccesstime"]);
if (t.Seconds > 8)
{
dr.Delete();[转载]

}
}
dt.AcceptChanges();

this.Label1.Text = dt.Rows.Count.ToString();
[转载]

搜索更多相关主题的帖子: 统计 Application DataTable dtnew online 
2007-03-23 14:20



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-126139-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.108226 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved