跪求解决问题的答案 !!急啊 !哪位前辈指点迷津一下!
错误提示:用户代码未处理 System.NullReferenceException
Message="未将对象引用设置到对象的实例。"
Source="App_Web_ofxwnkqm"
StackTrace:
在 User_Home.Page_Load(Object sender, EventArgs e) 位置 e:\Webshop\User\Home.aspx.cs:行号 33
在 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:
源代码
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
public partial class User_Home : System.Web.UI.Page
{
DBClass dbObj = new DBClass();
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Uname"] != null)
{
LinkloginButton.Visible = false;
}
SqlConnection conn = dbObj.GetConnection();
if (this.DropDownList1.SelectedIndex == 0)
{
string selectsql = "SELECT [GoodsUrl], [商品名], [价格] FROM [tb_GoodsInfo]";
SqlCommand cmd = new SqlCommand(selectsql, conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet dsPubs = new DataSet();
conn.Open();
adapter.Fill(dsPubs, "GooodsInfo");
this.GridView1.DataSource = dsPubs.Tables["GoodsInfo"].DefaultView;
this.GridView1.DataBind();
conn.Close();
}
else
{
string selectsql="SELECT [GoodsUrl], [商品名], [价格] FROM [tb_GoodsInfo] WHERE 类别='"+this.DropDownList1.SelectedValue.ToString()+"'";
SqlCommand cmd = new SqlCommand(selectsql, conn);
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
conn.Open();
adapter.Fill(ds, "GooodsInfo");
this.GridView1.DataSource = ds.Tables["GoodsInfo"].DefaultView;
this.GridView1.DataBind();
conn.Close();
}
}
protected void LinkloginButton_Click(object sender, EventArgs e)
{
Response.Redirect("~/User/Login.aspx");
}
}