日期:2014-05-17  浏览次数:20388 次

未找到引用对象的实例,在线等~~~
网页传参,有两个参数,代码如下,两个参数 不是同时传过来的
代码如下:

这两个参数的意思是在其他页面点击链接,有的链接传的是categoryId,有的是Id,所有一次只获取其中一个,但是不确定是哪个,所有总有一个找不到对象,我判断了,断点总是没到下面判断就报异常,请高手指点!

private void DataRead()
  {  
  //categoryId为 baike_category表主键
  string categoryId = Request.QueryString["categoryId"].ToString();
  //newsId为baike_details表主键
  string newsId = Request.QueryString["Id"].ToString();


   


  BaikeDetailBusiness business = new BaikeDetailBusiness();



  if (!string.IsNullOrEmpty(newsId))
  {

  BaikeDetail content = business.GetEntity(int.Parse(newsId));
  ltitle.Text = content.Category_name;
  if (content.CreateDate.HasValue)
  {


  lCreateDate.Text = "时间:" + content.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  }
  else
  {
  lCreateDate.Text = "";
  }
  ltitle.Text = content.BaikeName;
  lContent.Text = content.Description;

  lCategoryName.Text = new BaikeCategoryBusiness().GetEntity(content.CategoryId).CategoryName;
  business.UpdateClickNumber(int.Parse(newsId));
  }
  else if (!string.IsNullOrEmpty(categoryId))
  {
  BaikeDetail content2 = business.GetEntity2(int.Parse(categoryId));
  ltitle.Text = content2.Category_name;
  if (content2.CreateDate.HasValue)
  {


  lCreateDate.Text = "时间:" + content2.CreateDate.Value.ToString("yyyy-MM-dd HH:mm:ss");
  }
  else
  {
  lCreateDate.Text = "";
  }
  ltitle.Text = content2.BaikeName;
  lContent.Text = content2.Description;

  lCategoryName.Text = new BaikeCategoryBusiness().GetEntity(int.Parse(categoryId)).CategoryName;
  business.UpdateClickNumber2(int.Parse(categoryId));
  }
  }

------解决方案--------------------
C# code
string categoryId = Request.QueryString["categoryId"] as string;
string newsId = Request.QueryString["Id"] as string;
换成这样就可以了

------解决方案--------------------
if (!string.IsNullOrEmpty(Request.QueryString["categoryId"]) && !string.IsNullOrEmpty(Request.QueryString["ID"]))
{ }
else 跳转到指定页面
------解决方案--------------------
if (!string.IsNullOrEmpty(Request.QueryString["Id"].ToString()))
else if (!string.IsNullOrEmpty(Request.QueryString["categoryId"].ToString()))
 
将这两行的.ToString()去掉
------解决方案--------------------
你那F11调试到这个方法试试