ASP.NET 未将对象引用设置到对象的实例.
因为前面没有定义session,所以后面没法取值,我应该怎么修改?if(Session["userid"].ToString()==null){LinkButton1.T...
因为前面没有定义session,所以后面没法取值,我应该怎么修改?
if (Session["userid"].ToString() == null)
{
LinkButton1.Text = "登录";
}
else
{
string uid = Session["userid"].ToString();
OleDbConnection mycon = new OleDbConnection();
mycon.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("data/agmn.mdb");
mycon.Open();
OleDbCommand com = new OleDbCommand();
com.Connection = mycon;
com.CommandText = "select * from [user] where userid=" + uid;
OleDbDataReader mydr = com.ExecuteReader();
if (mydr.HasRows)
{
mydr.Read();
LinkButton1.Text = mydr["nickname"].ToString();
}
mycon.Close();
} 展开
if (Session["userid"].ToString() == null)
{
LinkButton1.Text = "登录";
}
else
{
string uid = Session["userid"].ToString();
OleDbConnection mycon = new OleDbConnection();
mycon.ConnectionString = "provider=microsoft.jet.oledb.4.0;data source=" + Server.MapPath("data/agmn.mdb");
mycon.Open();
OleDbCommand com = new OleDbCommand();
com.Connection = mycon;
com.CommandText = "select * from [user] where userid=" + uid;
OleDbDataReader mydr = com.ExecuteReader();
if (mydr.HasRows)
{
mydr.Read();
LinkButton1.Text = mydr["nickname"].ToString();
}
mycon.Close();
} 展开
1个回答
2015-05-26
展开全部
if (Session["userid"] == null)
{
LinkButton1.Text = "登录";
}
else
{
string uid = Session["userid"].ToString();
.....
吧第一行改了就行了
{
LinkButton1.Text = "登录";
}
else
{
string uid = Session["userid"].ToString();
.....
吧第一行改了就行了
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询