整理一下:
protected void Session_End(Object sender, EventArgs e)
{
if(Session["UserName"]!=null)
{
string userName = (string)Session["UserName"];
怎末编("delete online where username = "+username);
}
}

解决方案 »

  1.   

    高错了吧/应该是
    if(Session["UserName"]==null)
    {
    string userName = (string)Session["UserName"];
    string sql="delete online where username = "+username;
                      …………
    }
      

  2.   

    new AvatarLibrary.Common.CommonData().Query2Bool("delete online where username = "+username);这句话是什末意思?能行莫?
      

  3.   

    我在Global.asax.cs中创建sqlDataAdapter就可以运行sql吧
      

  4.   

    搂主可以先建一个简单的类库,如AvatarLibrary,里面有个文件夹Common,然后在此文件夹下新建一个类文件CommonData.cs,此文件专门用于处理数据层的操作,此文件代码如下:
    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);
      

  5.   

    当然你也可以不用自己建类库,可以在你的Web项目中建一个类文件(如:CommonData.cs),然后在此文件中添加上述代码,使用时如下:new CommonData().Query2Bool("delete from online where username = "+username);
    总之就是,先实例化你创建的类,然后调用其中的方法。
    ====================================================
    //数据库连接字符串
    public static string StrConn = System.Configuration.ConfigurationSettings.AppSettings["StrConn"];
    这个是从web.config中获得数据库连接字符串
    =========================================================
    呵呵!