this.textBox1.Text = dataGridView1.Rows[i].Cells[j].Value.ToString();
或者
this.textBox2.Text = myreader[i].ToString();这些都是通过列号来取值的,但是万一数据表重新排过序或者列很多,要取某列的值就很麻烦,能不能通过字段名取某列的值啊

解决方案 »

  1.   

    this.dataGridView1.Rows[i].Cells["ColuName"].ToString();
      

  2.   

    sorry
    this.dataGridView1.Rows[i].Cells["ColuName"].Value.ToString();
      

  3.   

    string stemp = reader["id"].ToString();
      

  4.   

    你这个返回
    DataGridViewTextBoxCell { ColumnIndex=3, RowIndex=3 }
      

  5.   

    this.dataGridView1.Rows[i].Cells["ColuName"].Value.ToString();这个对了,谢谢
    但string stemp = reader["id"].ToString();还是不对啊
      

  6.   

    to 但string stemp = reader["id"].ToString();还是不对啊reader["id"]//id 依旧是数据库字段
      

  7.   

    reader["id"]//id 依旧是数据库字段??id是int型,怎么会是数据库字段呢,反正运行就报错
      

  8.   

    reader["id"]//id 依旧是数据库字段??reader["ColuName"].ToString();这样写 ok 了吧  我意思reader[]索引 同样提供name索引
      

  9.   

    datagridView.Rows[i].Collum["Name"].value.Tostring