本文介绍了我想获得标签的行值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
str = "select CAT_NO from CATEGORY1";
cmd = new SqlCommand(str, cn);
sda = new SqlDataAdapter(cmd);
ds = new DataSet();
sda.Fill(ds, "CATEGORY1");
dt = ds.Tables[0];
foreach (DataRow dr1 in dt.Rows)
{
label1.Text = dr1[0].ToString();
label2.Text = dr1[0].ToString();
}
该表包含两行sub1和sub2,label1应显示sub1,标签2显示sub2但使用此代码,两个标签都显示sub2
The table contains two rows sub1 and sub2 and the label1 should display sub1 and label 2 display sub2 but using this code both the labels displays sub2
推荐答案
label2.Text = dr1[1].ToString();
哦我现在看到了(或者至少我希望我现在知道你的意思),你有两行一列(CAT_NO列)吧?
在这种情况下试试这个:
Oh I see now (or at least I hope I know now what you mean), you have two rows with a single column (that CAT_NO column) right?
In that case try this:
dt = ds.Tables[0];
label1.Text = dt.Rows[0][0].ToString();
label2.Text = dt.Rows[1][0].ToString();
这篇关于我想获得标签的行值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!