跪求解决问题的答案 !!急啊 !哪位前辈指点迷津一下!

zwxll5200 2012-04-11 12:55:17
错误提示:用户代码未处理 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");
}
}
...全文
118 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
熙风 2012-04-11
  • 打赏
  • 举报
回复
adapter.Fill(ds, "GooodsInfo");
test2050 2012-04-11
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]
GooodsInfo

上下名字不一致,多了个o
[/Quote]
法眼啊
熙风 2012-04-11
  • 打赏
  • 举报
回复
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();
}
熙风 2012-04-11
  • 打赏
  • 举报
回复
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();
}
熙风 2012-04-11
  • 打赏
  • 举报
回复
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();
}

test2050 2012-04-11
  • 打赏
  • 举报
回复
调试代码33行是哪一行错误,代码是什么。
熙风 2012-04-11
  • 打赏
  • 举报
回复
GooodsInfo

上下名字不一致,多了个o
熙风 2012-04-11
  • 打赏
  • 举报
回复
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();
}
bdmh 2012-04-11
  • 打赏
  • 举报
回复
告诉你第33行,调试,看看哪个对象为空,不可访问
事理 2012-04-11
  • 打赏
  • 举报
回复
试试dsPubs.Tables[0].DefaultView;

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧