How can I manually add data to a dataGridView?

前端 未结 5 633
梦谈多话
梦谈多话 2020-12-16 19:23

I\'m trying to run this code, and I get an exception:

Index was out of range. Must be non-negative and less than the size of the collection. Param

5条回答
  •  悲哀的现实
    2020-12-16 19:51

    My version of this:

                    OracleCommand cmd = new OracleCommand(commandText, _oraConn);
                    OracleDataReader dr = cmd.ExecuteReader();
    
                    int i = 0;
                    while (dr.Read())
                    {
                        DataGridViewRow row = new DataGridViewRow();
                        row.CreateCells(dataGridView1);
    
    
                        row.Cells[0].Value = dr.GetValue(0).ToString();
                        row.Cells[1].Value = dr.GetValue(1).ToString();
                        row.Cells[2].Value = dr.GetValue(2).ToString();
                        row.Cells[3].Value = dr.GetValue(3).ToString();
                        row.Cells[4].Value = dr.GetValue(4).ToString();
                        row.Cells[5].Value = dr.GetValue(5).ToString();
    
                        dataGridView1.Rows.Add(row);
    
                        //MessageBox.Show( dr.GetValue("vz_id").ToString());
                        i++;
                    };
    

    Thanks for your answers.

提交回复
热议问题