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

关于主从表的问题(求帮助)
public partial class WebForm2 : System.Web.UI.Page
  {
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!Page.IsPostBack)
  {
  string SQL = "select c.*,d.fName AS fContractType from tContractGoods a,tContract c,(select * from tContractType) d where a.fID=c.fID and c.fContractType = d.fType";
  GridView1.DataSource = Binding(SQL);
  GridView1.DataKeyNames = new string[] { "c.fID" };
  GridView1.DataBind();
  }
  }
  protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
  {
  string OrderID = Convert.ToString(GridView1.SelectedValue);
  string SQL = "select a.*,c.* from tContractGoods a ,tContract c where a.fGoodsType=2 and a.fID='" + OrderID + "'";
  GridView2.DataSource = Binding(SQL);
  GridView2.DataBind();
  }

  protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
  {

  }
  /**/
  /// <summary>
  /// 执行SQL语句返回一个数据表
  /// </summary>
  /// <param name="SQL">所要执行的SQL语句</param>
  /// <returns>DataTable</returns>
  protected DataTable Binding(string SQL)
  {
   
SqlConnection myConn = new               SqlConnection(ConfigurationManager.ConnectionStrings["AppConnectionString1"].ConnectionString);
  DataTable dt = new DataTable();
  SqlDataAdapter myAdapter = new SqlDataAdapter(SQL, myConn);
  myAdapter.Fill(dt);
  return dt;

  }

出现如下问题;

用户代码未处理 System.NullReferenceException
  Message="未将对象引用设置到对象的实例。"
  Source="hager"
  StackTrace:
  在 hager.WebForm2.Binding(String SQL) 位置 C:\Documents and Settings\develop\My Documents\Visual Studio 2008\Projects\hager\hager\WebForm2.aspx.cs:行号 47
  在 hager.WebForm2.Page_Load(Object sender, EventArgs e) 位置 C:\Documents and Settings\develop\My Documents\Visual Studio 2008\Projects\hager\hager\WebForm2.aspx.cs:行号 21
  在 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
  在 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
  在 System.Web.UI.Control.OnLoad(EventArgs e)
  在 System.Web.UI.Control.LoadRecursive()
  在 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 

请问是什么问题该如何解决?


------解决方案--------------------
给分啊,。呵呵