整理一下:
protected void Session_End(Object sender, EventArgs e)
{
if(Session["UserName"]!=null)
{
string userName = (string)Session["UserName"];
怎末编("delete online where username = "+username);
}
}
protected void Session_End(Object sender, EventArgs e)
{
if(Session["UserName"]!=null)
{
string userName = (string)Session["UserName"];
怎末编("delete online where username = "+username);
}
}
if(Session["UserName"]==null)
{
string userName = (string)Session["UserName"];
string sql="delete online where username = "+username;
…………
}
using System;
using System.Data;
using System.Data.SqlClient;namespace AvatarLibrary.Common
{
/// <summary>
/// CommonData 的摘要说明。
/// </summary>
public class CommonData
{
public CommonData()
{
//
// TODO: 在此处添加构造函数逻辑
//
} //数据库连接字符串
public static string StrConn = System.Configuration.ConfigurationSettings.AppSettings["StrConn"];
//
#region//返回Bool:public bool Query2Bool(string cmdText)
public bool Query2Bool(string cmdText)
{
try
{
SqlCommand myCmd=new SqlCommand(cmdText,new SqlConnection(StrConn));
myCmd.CommandType=CommandType.Text;
myCmd.Connection.Open();
myCmd.ExecuteNonQuery();
myCmd.Connection.Dispose();
myCmd.Dispose();
return true;
}
catch(Exception e1)
{
return false;
}
}
#endregion
}
}==================================================
然后在你的其他Web项目中引用此类库的DLL文件,调用时就是下面的代码了:
new AvatarLibrary.Common.CommonData().Query2Bool("delete from online where username = "+username);
总之就是,先实例化你创建的类,然后调用其中的方法。
====================================================
//数据库连接字符串
public static string StrConn = System.Configuration.ConfigurationSettings.AppSettings["StrConn"];
这个是从web.config中获得数据库连接字符串
=========================================================
呵呵!