我写了购物车类DB.CS;代码如下:
public void goddataset(string id)
{
if (Session["bus"] == null)
{
Hashtable ht = new Hashtable();
ht.Add(id,1);
Session["bus"] = ht;
dafill(ht);
}
else
{
Hashtable ht = (Hashtable)Session["bus"];
if (ht[id] == null)
{
ht[id] = 1;
}
else
{
ht[id] = (int)ht[id] + 1;
}
Session["bus"] = ht;
dafill(ht);
}
}
public void dafill(Hashtable ht)
{
godset.Clear();
foreach (DictionaryEntry de in ht )
{
hh =ht[de.Key.ToString ()].ToString ();
SqlDataAdapter datap = new SqlDataAdapter("select * from tb_goods where id='" + de.Key.ToString() + "'", System.Configuration.ConfigurationSettings.AppSettings["constr"]);
if (datap != null)
{
datap.Fill(godset);
}
}
}在首页index.aspx登陆成功后点击购买后:运行下面这段代码:
DB sh = new DB();
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();//商品绑定用datalist;id为获取商品ID;
//Response.Redirect("shoppingcar.aspx");
sh.goddataset(id);//调用DB.CS中的goddataset()函数;可是出现错误!!提示:
未将对象引用设置到对象的实例。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 行 53: string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();行 54: //Response.Redirect("shoppingcar.aspx");行 55: sh.goddataset(id);行
56: } 还有:点击购物后,跳转到shopcar.aspx,我用response.redirect();跳过去后,购物车中并没有购物信息?~!~这怎么回事,高手帮忙解决下~~
各位帮忙看看,怎么回事,弄了好久,没有找到错误,QQ:413763818也可详细交流;谢谢了
public void goddataset(string id)
{
if (Session["bus"] == null)
{
Hashtable ht = new Hashtable();
ht.Add(id,1);
Session["bus"] = ht;
dafill(ht);
}
else
{
Hashtable ht = (Hashtable)Session["bus"];
if (ht[id] == null)
{
ht[id] = 1;
}
else
{
ht[id] = (int)ht[id] + 1;
}
Session["bus"] = ht;
dafill(ht);
}
}
public void dafill(Hashtable ht)
{
godset.Clear();
foreach (DictionaryEntry de in ht )
{
hh =ht[de.Key.ToString ()].ToString ();
SqlDataAdapter datap = new SqlDataAdapter("select * from tb_goods where id='" + de.Key.ToString() + "'", System.Configuration.ConfigurationSettings.AppSettings["constr"]);
if (datap != null)
{
datap.Fill(godset);
}
}
}在首页index.aspx登陆成功后点击购买后:运行下面这段代码:
DB sh = new DB();
string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();//商品绑定用datalist;id为获取商品ID;
//Response.Redirect("shoppingcar.aspx");
sh.goddataset(id);//调用DB.CS中的goddataset()函数;可是出现错误!!提示:
未将对象引用设置到对象的实例。 说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 异常详细信息: System.NullReferenceException: 未将对象引用设置到对象的实例。源错误: 行 53: string id = DataList1.DataKeys[e.Item.ItemIndex].ToString();行 54: //Response.Redirect("shoppingcar.aspx");行 55: sh.goddataset(id);行
56: } 还有:点击购物后,跳转到shopcar.aspx,我用response.redirect();跳过去后,购物车中并没有购物信息?~!~这怎么回事,高手帮忙解决下~~
各位帮忙看看,怎么回事,弄了好久,没有找到错误,QQ:413763818也可详细交流;谢谢了
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货