计算出了数据库中所有的数据记录,然后FOR循环显示出数据库中某一列的所有数据。怎么我的FOR显示不出来呢?
string sqlrount="select count(*) from Gold_Channel";
OleDbCommand mycomm1=new OleDbCommand(sqlrount,Myconn);
Myconn.Open();
int RecordCount=Convert.ToInt32(mycomm1.ExecuteScalar());//技算出了总数集
Myconn.Close();
for(int i=0;i<=RecordCount;i++)//循环显示某一列中的所有字段
{
DataRow MyRow;
MyRow=ds.Tables["table1"].Rows[i];
Label1.Text+=MyRow[i].ToString();
}我这个数据库里就2条记录,运行以上代码,它居然报错说在位置 2 处没有任何行。 
雾水中……希望大家帮我一下,谢谢了

解决方案 »

  1.   

    i<=RecordCount改为i<=RecordCount-1.从0开始的。
      

  2.   

    写的什么乱七八糟的......dim row as datarow
    for each row in ds.table(0).rows
      label1.text += row.item(你的列序号).tostring
    next或者
    dim i as integer
    for i = 0 to ds.table(0).rows.count-1
      label1.text += ds.table(0).rows.item(列序号)
    next
      

  3.   

    Label1.Text+=MyRow[i].ToString();
    要改成Label1.Text+=MyRow[1].ToString();就显示出来了。。呵呵,搞定,谢谢了