读书人

未将对象引用设置到对象的实例,该怎么

发布时间: 2013-10-21 17:03:30 作者: rapoo

未将对象引用设置到对象的实例
string userName = Session["name"].ToString();
DB.BLL.DBManager showsource = new DB.BLL.DBManager();
DataSet ds = new DataSet();
ds = showsource.ShowSource(userName);
if (ds != null)
{
GridView1.DataSource = ds;
}
不懂怎么解决
[解决办法]
Session["name"]为空
[解决办法]
判断Session["name"]为空就不走下去啦
[解决办法]


if(Session["name"] != null)
{
string userName = Session["name"].ToString();
DB.BLL.DBManager showsource = new DB.BLL.DBManager();
DataSet ds = new DataSet();
ds = showsource.ShowSource(userName);
if (ds != null)
{
GridView1.DataSource = ds;
}
}

读书人网 >.NET Framework

热点推荐