日期:2014-05-20  浏览次数:21095 次

求高手!!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class photoAlbum : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  { 
  if (!IsPostBack)
  {
  Bing();
  }
  }
  public void Bing()
  {
  string SQL = "select * from TypeIMG ";
  Jerry.SQLServer db = new Jerry.SQLServer();
  DataSet ds = db.select(SQL);
  Repeater1.DataSource = ds.Tables["content"].DefaultView; Repeater1.DataBind();
  }
}


运行时出现未将对象引用设置到对象的实例。到底是哪里出现错误了啊????

------解决方案--------------------
探讨
if(ds !=null)
{
Repeater1.DataSource = ds.Tables[0].DefaultView;
Repeater1.DataBind();

}

------解决方案--------------------
C# code

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class photoAlbum : System.Web.UI.Page
{
   protected void Page_Load(object sender, EventArgs e)
   { 
     if (!IsPostBack)
     {
        Bing();
     }
  }

  public void Bing()
  {
      string SQL = "select * from TypeIMG ";
      Jerry.SQLServer db = new Jerry.SQLServer();
      DataSet ds = db.select(SQL);
      Repeater1.DataSource = ds;
      Repeater1.DataBind();
   }
}