首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

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

2012-04-03 
DataReader求救问题,请各位大侠帮忙。SqlConnectionconClass1.lj()SqlCommandcmnewSqlCommand( select*

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())
{
}

热点排行