各位帮帮忙
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>");
}
请问怎么解决啊???????????????????????????????????????????????????????????????????????
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>");
}
请问怎么解决啊???????????????????????????????????????????????????????????????????????
解决方案 »
- 谁知道在哪可下到用WCF建立的项目实例???
- 关于updatepanel的问题
- 为什么Repeater里的控件,总是不能动态委托事件呢?
- <%# 如何在我的网页中播放背景音乐MP3,...要求在不同的网页中转换的时候,音乐不间断
- 为什么DataList显示图片换行之间有间隙
- !用HttpRequest进行HTTP Post操作时遇到一些问题
- 我可以发布一个完全不带源码文件.cs的asp.net站点吗?你们是如何架构站点,以便发布完全不带源码的website的呢?
- 页面提交问题
- 未能访问“CDO.Message”对象
- 微软的Microsoft.Web.UI.WebControls.dll目录树控件是不是有BUG啊?
- 真烦! 又是邮件问题...............
- net向javascript方法传值问题
{}
else
{
string strid = Sessio["userid"].ToString();
}
你不判断的话,session空的话肯定报错的