首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

I need your help!come on解决办法

2012-01-14 
I need your help!!!!!!!!!!!!!!!!!!!!!!!!!!!!come on各位帮帮忙protected void Button2_Click(object se

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空的话肯定报错的

热点排行