DataSet ds_hwxx = sqlhelper.GetDataSet("select hwmc,hwzjs,hwztj,hwzzl,dj,bxf,bxe from hwxx where jydbh='"+jydbh+"'");             int count = ds_hwxx.Tables[0].Rows.Count;
             if (count == 1)
             {
                 hwmc0 = ds_hwxx.Tables[0].Rows[0].ItemArray[0].ToString();
                 .......
              }
             else if (count == 2)
             {
                 hwmc0 = ds_hwxx.Tables[0].Rows[0].ItemArray[0].ToString();
                 hwmc1 = ds_hwxx.Tables[0].Rows[1].ItemArray[1].ToString();
                 ..............
             }else
             {
                hwmc0 = ds_hwxx.Tables[0].Rows[0].ItemArray[0].ToString();
                hwmc1 = ds_hwxx.Tables[0].Rows[1].ItemArray[1].ToString();
                hwmc2 = ds_hwxx.Tables[0].Rows[1].ItemArray[2].ToString();
                .....
              }

解决方案 »

  1.   

    我是要把他一行一行的输出到票据上面,一行数据只显示一行,二行就显示二行
    怎么会当只有一行数据的时候也显示了三行数据呢?
    <div id="hwmc0"
    style="position:absolute; left: 81px; top: 192px; width: 68px; font-size:10pt;"><%=hwmc0 %></div>
    <div id="hwmc1"
    style="position:absolute; left: 81px; top: 192px; width: 68px; font-size:10pt;"><%=hwmc1 %></div>
    <div id="hwmc2"
    style="position:absolute; left: 81px; top: 192px; width: 68px; font-size:10pt;"><%=hwmc2 %></div>这是我在票据上放置的三行数据div
      

  2.   

    如果用的是dataGridView1,改一下
    dataGridView1.AllowUserToAddRows = false试试
      

  3.   

    select hwmc,hwzjs,hwztj,hwzzl,dj,bxf,bxe from hwxx where jydbh='"+jydbh+"'
    放数据库里看有几行
      

  4.   

    数据肯定是只有一行了,我知道了 
    我声明了public 变量
    public string hwmc0 = string.Empty;
        public string hwmc1 = string.Empty;
        public string hwmc2 = string.Empty;
        public int jianshu0 = 0 ;
        public int jianshu1 = 0 ;当只有一行数据的时候 声明为0值的变量也会显示出来 ,如何隐藏当值为0时的变量呢???
    <div id="hwmc0"
    style="position:absolute; left: 81px; top: 192px; width: 68px; font-size:10pt;"><%=hwmc0 %></div>
    <div id="hwmc1"
    style="position:absolute; left: 81px; top: 192px; width: 68px; font-size:10pt;"><%=hwmc1 %></div>
    <div id="hwmc2"
    style="position:absolute; left: 81px; top: 192px; width: 68px; font-size:10pt;"><%=hwmc2 %></div>
      

  5.   

    改成private 然后生出容器get set
    不要赋初值
      

  6.   


    <%=string.IsNullOrEmpty(hwmc0)?"":hwmc0 %>
      

  7.   

    protected string hwmc0 = string.Empty;  //私有成员前台无法访问的if (count == 1)
      {
      hwmc0 = ds_hwxx.Tables[0].Rows[0].ItemArray[0].ToString();
      .......
      }
      else if (count == 2)
      {
      hwmc0 = ds_hwxx.Tables[0].Rows[0].ItemArray[0].ToString();
      hwmc1 = ds_hwxx.Tables[0].Rows[1].ItemArray[0].ToString();
      ..............
      }else
      {
      hwmc0 = ds_hwxx.Tables[0].Rows[0].ItemArray[0].ToString();
      hwmc1 = ds_hwxx.Tables[0].Rows[1].ItemArray[0].ToString();
      hwmc2 = ds_hwxx.Tables[0].Rows[2].ItemArray[0].ToString();
    你应该只取货物名称,也就是第一列,应该都是ItemArray[0]才对
    Rows[]对应行索引,ItemArray[0]对应的是列索引PS:最好用一个循环把值取出来,因为只有行号不同
      

  8.   


    应该是判断int 和decimal型才对
    如果是string 的话 自动就为空了
      

  9.   

    我现在要取的是 int型 jianshu 要如何判断当为0 时 不显示