读书人

DataReader求救有关问题请各位大侠帮

发布时间: 2012-04-03 12:38:19 作者: rapoo

DataReader求救问题,请各位大侠帮忙。
SqlConnection con = Class1.lj();
SqlCommand cm = new SqlCommand( "select * from xg ", con);
SqlDataReader red = cm.ExecuteReader();
red.Read();
string[] sd = new string[2];
sd[0] = red.IsDBNull(0) ? " " : red.GetValue(0).ToString();
sd[1] = red.IsDBNull(1) ? " " : red.GetValue(1).ToString();
for (int i = 0; i < this.GridView1.Rows.Count; i++)
{

string bh = " ";
string sj = " ";
bh = ((Label)this.GridView1.Rows[i].Cells[0].FindControl( "lbl1 ")).Text;
sj = ((Label)this.GridView1.Rows[i].Cells[5].FindControl( "lbl5 ")).Text;
if (bh == sd[0].ToString() && sj == sd[1].ToString())
{
this.GridView1.Rows[i].Cells[3].ForeColor = Color.LimeGreen;
}
}
con.Close();
red.Close();



我要比对两个表中的数据是否一样,如果一样则GridView1里面的某一列某一行的值变颜色,可是目前只有查出来的第一个的值颜色变其他的都不变,我觉得是red的事情,他好他的值一直都是第一个数据的值如何让其做完一个循环之后让其一个接着一个往下走呢,逐条判断呢?

[解决办法]
while( red.Read())
{
}

读书人网 >asp.net

热点推荐