表t1中有共5列(c1,c2,c3,c4,c5)c2列中的值分别为(a,b,c...)我想做成这样,程序运行时把c2列的数据一条条读出来,显示如下:
abc[0]="a"
abc[1]="b"
abc[2]="c"我原来的代码是这样的:
sql="select * from t1"//省略部分代码dr为SqlDataReaderfor (int i = 0; i<dr.FieldCount; i++)
{
    htmlStr.Append(string.Format("abc[{0}]='{1}';",i,dr[1])); 
}
请帮忙一下以上程序错在哪里?

解决方案 »

  1.   

    有错误提示吗?贴出来
    还有 DataReader 最好不要用来循环
    用 DataSet 这样的
      

  2.   

    abc[]这个是数组。。dr.FieldCount这个是字段数目。。你要的应该是行数。。
      

  3.   

    string[] sArray;
    while(reader.Read())
    {
        string s = reader.GetString(1); //读第二列
        sArray = s.Slipt(',');
    }
      

  4.   

    int i=0;
    while(dr.Read())

        htmlStr.Append(string.Format("abc[{0}]='{1}';",i++,dr[1]));