首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

大家可以帮小弟我看看这段代码有什么错吗?为什么一直报找不到tables 0

2012-05-28 
大家可以帮我看看这段代码有什么错吗?为什么一直报找不到tables 0public partial class gouwuche : System

大家可以帮我看看这段代码有什么错吗?为什么一直报找不到tables 0
public partial class gouwuche : System.Web.UI.Page
  {
  DataTable cart;
  Double TtlPrice;
  BLL.goods goodsbll = new BLL.goods();
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!Page.IsPostBack)
  {
  Image9.Visible = false;
  LabMessage.Visible = false;

  shoplist();
  }
  }
  protected void shoplist()
  {
  Hashtable Hash;
  if (Session["car"] == null)
  {
  Hash = new Hashtable();
  }
  else
  {
  Hash = (Hashtable)Session["car"];
  }
  if (Hash.Count == 0)
  {
  Image9.Visible = true;
  LabMessage.Visible = true;
  LabMessage.Text = "您还没有购物呢?赶快购物吧!";
  }

  string[] ArrKey = new string[Hash.Count];
  int[] ArrVal = new int[Hash.Count];
  string Goods = "('";
  Hash.Keys.CopyTo(ArrKey, 0);
  Hash.Values.CopyTo(ArrVal, 0);
  int k = 0;
  for (int j = 0; j < ArrKey.Length; j++)
  {
  if (k > 0) Goods += "','"; k++;
  Goods += ArrKey.GetValue(j).ToString();
  }
  Goods += "')";


  DataSet ds = goods.GetList("G_No in" + Goods);

  DataTable Table1 = new DataTable();
  Table1 = ds.Tables[0] ;
  //Table1 = ds.Tables["Goods"];
  Table1.Columns.Add(new DataColumn("Number", System.Type.GetType("System.Int32")));

  DataColumn[] Keys = { Table1.Columns["ID"] };
  Table1.PrimaryKey = Keys;
  foreach (string X in Hash.Keys)
  {
  Table1.Rows.Find(X)["Number"] = Hash[X];

  }
  Table1.Columns.Add(new DataColumn("Label1", System.Type.GetType("System.Double"), "price*Number"));


  for (int I = 0; I < Table1.Rows.Count; I++)
  {

  TtlPrice += Convert.ToDouble(Table1.Rows[I]["price"]);

  }

  Label1.Text = TtlPrice.ToString();
  Session["Total"] = Label1.Text.ToString();
  GridView2.DataSource = Table1.DefaultView;
  GridView2.DataBind();

  }
  protected void GridView2_RowCommand(object sender, GridViewCommandEventArgs e)
  {
  Hashtable Hash;
  if (Session["car"] == null)
  {
  Hash = new Hashtable();
  }
  else
  {
  Hash = (Hashtable)Session["car"];
  }

  if (Hash.ContainsKey(e.CommandArgument))
  {
  Hash.Remove(e.CommandArgument);
  }
  LabMessage.Text = (string)e.CommandArgument;

  Session["car"] = Hash;
  shoplist();


  }
  protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
  {
  Response.Redirect("default.aspx");
  }
  protected void ImageButton5_Click(object sender, ImageClickEventArgs e)
  {

  if (GridView2.Rows.Count == 0)
  {
  LTP.Common.MessageBox.Show(this, "请先购物!");

  // Page.RegisterClientScriptBlock("e", "<script>alert('请先购物!')</script>");
  }
  else if (Session["username"] == null)
  {
  ScriptManager.RegisterStartupScript(this.ImageButton5, this.GetType(), "alertScript", "window.open('ssnotice.aspx');", true);
  //Response.Write("<script>alert('请先登录!');location.href='denglu.aspx'</script>");

  // Server.Transfer("userlogin.aspx");
  }
  else
  {

  Response.Redirect("pay1.aspx");
  }
  }
  }

[解决办法]
goods.GetList能得到正确的datatable吗,检查代码
[解决办法]
一步步调试,自己看下数据
[解决办法]

C# code
DataSet ds = goods.GetList("G_No in" + Goods);
[解决办法]
DataSet ds = goods.GetList("G_No in" + Goods);

这个取数据的格式写的好像有问题吧


[解决办法]
这代码表示压力山大,
[解决办法]
解决了,不错。
[解决办法]
探讨
C# code


DataSet ds = goods.GetList("G_No in" + Goods);


这段代码再看看,应该是没取到数据。

[解决办法]
单步调试吧
解决就好

热点排行