未将对象引用设置到对象的实例。using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class P_Message : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// Response.Write("<script language=javascript> alert('" + Session["Message_Title"].ToString() + "123" + "');</script>");
this.Title = "消息详细信息";
////////////////////////////
string sc = @"Data Source=.;Initial Catalog=classmate;Integrated Security=True";
SqlConnection Sql = new SqlConnection(sc);
Sql.Open();
string str1 = "update message_board set Views=Views+1 where MesTitle='"+Session["MesTitle"].ToString()+"'and Mespeople='"+Session["Mespeople"].ToString()+"'and Mestime='"+Convert.ToDateTime(Session["Mestime"].ToString())+"'and Mescontent='"+Session["Mescontent"].ToString()+"'";
string str = "select * from message_board where MesTitle= MesTitle='" + Session["MesTitle"].ToString() + "'and Mespeople='" + Session["Mespeople"].ToString() + "'and Mestime='" + Convert.ToDateTime(Session["Mestime"].ToString()) + "'and Mescontent='" + Session["Mescontent"].ToString() + "'";
try
{
SqlDataAdapter ada = new SqlDataAdapter(str, Sql);
DataSet data = new DataSet();
ada.Fill(data,"Message");
Label8 .Text = data.Tables[0].Rows[0]["MesTitle"].ToString();
Label9.Text = data.Tables[0].Rows[0]["Mespeople"].ToString();
Label10.Text = data.Tables[0].Rows[0]["Mestime"].ToString();
Label11.Text = data.Tables[0].Rows[0]["Mescontent"].ToString();
Label6.Text = data.Tables[0].Rows[0]["Views"].ToString();
SqlCommand command = new SqlCommand(str1, Sql);
command.ExecuteNonQuery();
}
catch (SqlException E)
{
Response.Write("<script Language=Javescript>alert('" + E.Message + "');history(-1);</script>");
}
finally
{
Sql.Close();
}
}
}
解决方案 »
- 求助Oracle长字符串读取的问题
- 如何把网络图片读取到bitmap变量中
- C# combobox的SelectedValueChanged事件问题???在线急等!!!!
- [求助]用WebBrowser可以对同一个论坛同时用不同的ID登录吗?
- 内网某台机器的80端口让外网机器来访问tcp,通过内网第三方发修改后的数据包是否可行
- 微软不厚道,大家说是不是?
- C#谁在做底层?比如通信行业的~~~
- 高分求助:两个数据结构相同,行记录数为50万的DataTable进行比较对比的问题
- 询问进程之间的通讯?
- vb.net中的isnumric函数在c#中是否有与之相匹配的函数,如果有应该是什么,谢谢
- 关于报表打印,report动态添加字段的问题!
- C#应用程序如何实现一条数据,在列表中分两行来操作(添加、修改)
string str1 = "update message_board set Views=Views+1 where MesTitle='"+Session["MesTitle"].ToString()+"'and Mespeople='"+Session["Mespeople"].ToString()+"'and Mestime='"+Convert.ToDateTime(Session["Mestime"].ToString())+"'and Mescontent='"+Session["Mescontent"].ToString()+"'";
这行报错
用参数不需要知道它的类型
只需要传值就行!~~~
if(Session["Mestime"]!=null)
..
可以用以下方法来规避问题
sql = " ... and ColumnName = '"+ (Session["aaa"]+"") +"'"
Mestime='"+Convert.ToDateTime(Session["Mestime"].ToString())如果Session["Mestime"]值为空,转化为日期的时候也是会报错的!
Convert.ToDateTime(Session["Mestime"].ToString()).ToString();
另外如果你传入的Session["Mestime"].ToString()如果为空,那么Convert.ToDateTime转换时会出错的,对于需是哟Convert进行转换的,最好先检查一下他们的值是否复核转换规则。
而且你现在这句话的转换其实没有一点意义,可以直接简化成Session["Mestime"].ToString(),这样即便为空也不会报错。如果你是想对日期格式进行转换,那么也应该是Convert.ToDateTime(Session["Mestime"].ToString()).ToString(“yyyyMMdd");或者Convert.ToDateTime(Session["Mestime"].ToString()).ToString(”yyyy年MM月dd日");
用追加字符串的形式。
当初我也经常因为string 为null 导致exception代码有够乱
那就不怕多写几行了
每个session 加个判断就好了