当前位置: 代码迷 >> ASP.NET >> I need your help!come on解决办法
  详细解决方案

I need your help!come on解决办法

热度:1442   发布时间:2013-02-25 00:00:00.0
I need your help!!!!!!!!!!!!!!!!!!!!!!!!!!!!come on
各位帮帮忙 
protected void Button2_Click(object sender, EventArgs e) 

if (Page.IsValid) 

string strid = Sessio["userid"].ToString();//这句出错了,错误是:未将对象引用设置到对象的实例。 
string strsubject = this.TextBox1.Text; 
string strmessage = this.TextBox2.Text; 
string strip = Request.UserHostAddress.ToString(); 
System.DateTime dateTime = DateTime.Now; 
string strDate = dateTime.ToString(); 
string strsql = "insert into newpost(subject,userid,message,ip,postime) values('" + strsubject + "','" + strid 
+ "','" + strmessage + "','" + strip + "','" + strDate + "')"; 
string str = "server=localhost;Initial catalog=bbs;Integrated Security=SSPI"; 
SqlConnection conn = new SqlConnection(str); 
conn.Open(); 
SqlCommand com = new SqlCommand(strsql, conn); 
com.ExecuteNonQuery(); 
conn.Close(); 
Response.Write("发表新主题成功,<a href='bbs.aspx'>返回论坛</a>"); 

请问怎么解决啊???????????????????????????????????????????????????????????????????????

------解决方案--------------------------------------------------------
你在之前的页面中或程序中没有给Session["userid"]赋值
------解决方案--------------------------------------------------------
if(Session["userid"]==null)
{}
else
{
string strid = Sessio["userid"].ToString();
}
你不判断的话,session空的话肯定报错的
  相关解决方案