积极答复者
未将对象引用设置到对象的实例

问题
-
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 NS_DBOP;public partial class Flow_ArchivesInfo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Bind();
}
}
public string path = null;
public string id = null;
public void Bind()
{
id = Request.QueryString["id"].ToString();
DataSet ds = new DBoperate().ExecuteQuery("select * from FlowDoc where ID=" + Convert.ToInt32(Request.QueryString["id"]),0,0,"flowdoc");
foreach(DataRow dr in ds.Tables[0].Rows)
{
this.lblTitle.Text = dr["Title"].ToString();
this.lblStep.Text = new DBoperate().ExecuteScalar("select Name from Flow where ID=" + Convert.ToInt32(dr["FlowID"])).ToString();
this.lblUrgent.Text =dr["IsUrgent"].ToString().Equals("0") ? "一般" :"重要";
this.lblUser.Text = new DBoperate().ExecuteScalar("select Name from Employee where Employeeid=" + dr["UserID"]).ToString();
this.lblPubDate.Text = dr["PubDate"].ToString();
this.txtcontent.Value = dr["Content"].ToString();
path = dr["Attachment"].ToString();
string[] a;
a = path.Split(';');
string[] AccIDList ={ "0" };
for (int i = 0; i < a.Length; i++)
{//LblAcc.Text += "<a href=\"upfiles/" + "+a[i]+"+ target=\"_blank\">" + a[i] + "</a>" + " " + " ";
this.lblAr.Text += "<a href=\"Files/"
+ a[i]
+ "\" target=\"_blank\">"
+ a[i]
+ "</a>" + " " + " ";
}
}string sql = "select * from FlowAction where ID in (select ActionID from FlowStep where FlowID in (select FlowID from FlowDoc where ID=" + Convert.ToInt32(Request.QueryString["id"]) + "))";
DataSet dsstep = new DBoperate().ExecuteQuery(sql, 0, 0, "flowstep");
string step = null;
foreach (DataRow drs in dsstep.Tables[0].Rows)
{
step += Convert.ToString(drs["Name"]) + "-->";
}
this.lblStep.Text = step + "完成";
}
}错误提示: id = Request.QueryString["id"].ToString();——>未将对象引用设置到对象的实例.
请问:这该怎样修改?
答案
全部回复
-
你好 请你检查你的URL中是否有如http://www.xxx.com/xxx.aspx?id=2222中的id
你可以通過下麵的代碼判斷
if(Request.QueryString["id"]!=null)
id=Request.QueryString["id"].ToString();
else
throw new Exception("id 為空!");
I see you~http://hi.baidu.com/1987raymondMy Blog~~~ -
Request.QueryString[“id"] 返回类型已经是 string,请不要对它再调用 ToString 方法,这是纯粹是画蛇添足,还带来了问题潜在的空引用问题
id = Request.QueryString[“id"]; // 可能 null,因为url 中没有查询参数 id
if(id != null) {
// your codes .....
}
问题要简单,错误须详细@错误/异常/堆栈信息+操作系统+软件版本+all the context of the issue Hope Helpful | http://www.leoworks.net