这个是什么意思,什么样的错误?
我在sql语句中将一个字段 as 商品数量 报“商品数量”出错,我商品数量列里有数据。
高手来指点指点!

解决方案 »

  1.   


    if (this.dataGridView1.SelectedRows.Count == 1)
                 {
                     //string ss = this.dataGridView1.CurrentRow.Cells[0].vToString();
                     sdr = add.sGetInventoryMxToEnterDat("where ghy_Jxc_InventoryMx.Id=" + this.dataGridView1.Rows[e.RowIndex].Cells["编号"].Value.ToString());
                     if (sdr.Read())
                     {
                         this.cmbGoodsName.Text = sdr["商品名称"].ToString();
                         this.txtGoodsLb.Text = sdr["商品类别"].ToString();
                         this.txtGoodsCd.Text = sdr["商品产地"].ToString();
                       //  MessageBox.Show(sdr["商品数量"].ToString() + "  ");
                         this.txtSl.Text = sdr["商品数量"].ToString();
                         this.txtMidCount.Text = sdr["中间单位数量"].ToString();                     this.txtSmalCount.Text = sdr["最小单位数量"].ToString();
                         this.txtGjDj.Text = sdr["购进单价"].ToString();
                         this.txtDbDj.Text = sdr["调拨单价"].ToString();
                         this.txtPfDj.Text = sdr["批发单价"].ToString();
                         this.cmbCk.Text = sdr["仓库名称"].ToString();
                         this.txtCw.Text = sdr["仓库地址"].ToString();
                     }             }把商品数量,中间单位数量,最小单位数量注释上后就正确了,我真是迷糊,是因为数量是int型
    我想这也不可能有影响啊!
      

  2.   

    你调式哈,看sdr里面有没有下面的列,是不是对应多了。 
      

  3.   

    这是存储过程exec('SELECT  distinct ghy_Jxc_InventoryMx.Id AS 编号, ghy_Jxc_InventoryMx.InventoryId AS 入库单号, ghy_Jxc_GoodsSet.GoodsMc AS 商品名称, 
                          ghy_Jxc_InventoryMx.Amount AS 商品数量, ghy_Jxc_InventoryMx.ItemCount AS 中间单位数量, ghy_Jxc_InventoryMx.BoxCount AS 最小单位数量, 
                          ghy_Jxc_InventoryMx.GjDj AS 购进单价, ghy_Jxc_InventoryMx.XsDj AS 销售单价, ghy_Jxc_InventoryMx.PfDj AS 批发单价, 
                          ghy_Jxc_InventoryMx.DbDj AS 调拨单价, ghy_Jxc_InventoryMx.ZdDj AS 最低单价, ghy_Jxc_wareHouse.WhName AS 仓库名称, 
                          ghy_Jxc_InventoryMx.Whaddress AS 仓库地址, ghy_Jxc_GoodsSetType.GoodsType AS 商品类别, ghy_Jxc_GoodsSet.GoodsCd as 商品产地
    FROM         ghy_Jxc_InventoryMx INNER JOIN
                          ghy_Jxc_GoodsSet ON ghy_Jxc_InventoryMx.GoodsId = ghy_Jxc_GoodsSet.GoodsId INNER JOIN
                          ghy_Jxc_wareHouse ON ghy_Jxc_InventoryMx.WareHouseId = ghy_Jxc_wareHouse.id INNER JOIN
                          ghy_Jxc_GoodsSetType ON ghy_Jxc_GoodsSet.GoodsType = ghy_Jxc_GoodsSetType.Id CROSS JOIN
                          ghy_Jxc_Gg '+@Whe+'')
      

  4.   

    你追踪得到的SQL语言 在SQL里面执行能通过吗
      

  5.   

    this.dataGridView1.Rows[e.RowIndex]的e.RowIndex是几?
    this.dataGridView1.Rows.Count是几?
      

  6.   

    这两个没问题e.RowIndex=1 Count也是1
      

  7.   

    如果Count是1,你传1进去行吗?数组从0开始。
      

  8.   

    “this.dataGridView1.Rows[e.RowIndex].Cells["编号"]”
    这个this.dataGridView1.Rows[]可是从0开始的!
      

  9.   

    我这个e。RowIndex是行的行号。private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
             {
                 if (this.dataGridView1.SelectedRows.Count == 1)
                 {
                     //string ss = this.dataGridView1.CurrentRow.Cells[0].vToString();
                     sdr = add.sGetInventoryMxToEnterDat("where ghy_Jxc_InventoryMx.Id=" + this.dataGridView1.Rows[e.RowIndex].Cells["编号"].Value.ToString());
                     if (sdr.Read())
                     {
                         this.cmbGoodsName.Text = sdr["商品名称"].ToString();
                         this.txtGoodsLb.Text = sdr["商品类别"].ToString();
                         this.txtGoodsCd.Text = sdr["商品产地"].ToString();
                       //  MessageBox.Show(sdr["商品数量"].ToString() + "  ");
                         this.txtSl.Text = sdr["商品数量"].ToString();
                         this.txtMidCount.Text = sdr["中间单位数量"].ToString();                     this.txtSmalCount.Text = sdr["最小单位数量"].ToString();
                         this.txtGjDj.Text = sdr["购进单价"].ToString();
                         this.txtDbDj.Text = sdr["调拨单价"].ToString();
                         this.txtPfDj.Text = sdr["批发单价"].ToString();
                         this.cmbCk.Text = sdr["仓库名称"].ToString();
                         this.txtCw.Text = sdr["仓库地址"].ToString();
                     }             }
             }
      

  10.   

    如果是从零开始的话,那我 this.cmbGoodsName.Text = sdr["商品名称"].ToString();
                         this.txtGoodsLb.Text = sdr["商品类别"].ToString();
                         this.txtGoodsCd.Text = sdr["商品产地"].ToString();
    也应该是错误的啊!
      

  11.   

    如果是要取选中行ID:

    sdr = add.sGetInventoryMxToEnterDat("where ghy_Jxc_InventoryMx.Id=" + this.dataGridView1.Rows[e.RowIndex].Cells["编号"].Value.ToString());
    改成
    sdr = add.sGetInventoryMxToEnterDat("where ghy_Jxc_InventoryMx.Id=" + this.dataGridView1.SelectedRows[0].Cells["编号"].Value.ToString());
    试试?
      

  12.   

    你if (this.dataGridView1.SelectedRows.Count == 1)是不是为了以“选中行的编号”为ID查询?
      

  13.   

    在我的dataGridview中有一行数据时 是好使的,不报错!
    还有在debug中运行exe时报错后单击继续,下一次又好使了,然后又不好使,在下一次又好使!
      

  14.   

    会不会是RowEnter事件闹的,你把方法放在[读取]按钮里试试?
      

  15.   

    在你17楼代码里,看不到sdr的声明,也许是事件并发访问共享资源造成的,你可以把sdr的声明挪到private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e){...}里试试。
      

  16.   

    这个和sdr的声明没关系把!要是有关系那么
    this.cmbGoodsName.Text = sdr["商品名称"].ToString();
    执行的时候就该报错了把!
      

  17.   


    private void dataGridView1_RowEnter(object sender, DataGridViewCellEventArgs e)
             {
                 if (this.dataGridView1.SelectedRows.Count == 1)
                 {
                     //string ss = this.dataGridView1.CurrentRow.Cells[0].vToString();
                     sdr = add.sGetInventoryMxToEnterDat("where ghy_Jxc_InventoryMx.Id=" + this.dataGridView1.Rows[e.RowIndex].Cells["编号"].Value.ToString());
                     if (sdr.Read())
                     {
     this.txtSl.Text = sdr["商品数量"].ToString();
                         this.txtMidCount.Text = sdr["中间单位数量"].ToString();                     this.txtSmalCount.Text = sdr["最小单位数量"].ToString();
                         this.cmbGoodsName.Text = sdr["商品名称"].ToString();
                         this.txtGoodsLb.Text = sdr["商品类别"].ToString();
                         this.txtGoodsCd.Text = sdr["商品产地"].ToString();
                       //  MessageBox.Show(sdr["商品数量"].ToString() + "  ");
                        
                         this.txtGjDj.Text = sdr["购进单价"].ToString();
                         this.txtDbDj.Text = sdr["调拨单价"].ToString();
                         this.txtPfDj.Text = sdr["批发单价"].ToString();
                         this.cmbCk.Text = sdr["仓库名称"].ToString();
                         this.txtCw.Text = sdr["仓库地址"].ToString();
                     }             }
             }
    将数量的移动到上就好使了 ,这是为什么呢?
      

  18.   

    我以前操作MYsql时也碰到过这种现象;有些地段放在前面读就没问题,放在后面就不行;
    还有人碰到这种现象吗?
    有知道原因的吗?
      

  19.   

    会不会是用中文的列名引起的,使用列名索引,最后也要调用SqlDataReader.GetOrdinal 方法将列名转为索引。