读书人

I need your help!come on解决办法

发布时间: 2012-01-14 20:02:35 作者: rapoo

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

读书人网 >asp.net

热点推荐