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();
.....
}
怎么会当只有一行数据的时候也显示了三行数据呢?
<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
dataGridView1.AllowUserToAddRows = false试试
放数据库里看有几行
我声明了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>
不要赋初值
<%=string.IsNullOrEmpty(hwmc0)?"":hwmc0 %>
{
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:最好用一个循环把值取出来,因为只有行号不同
应该是判断int 和decimal型才对
如果是string 的话 自动就为空了