OracleDataReader& datadridview列表

时间:2014-05-02 19:42:45

标签: c# oracle datagridview

我尝试从oracle db读取数据并将数据设置为datagridview组件但是我不知道datagridview的问题在哪里是空的,如果我在循环中测试读取器并获取值我看到所有行:

CODE:

Dbc dbc = new Dbc();
        dbc.connect();

        try
        {
            String sql = "SELECT * FROM " + _tname;
            OracleCommand comm = new OracleCommand(sql, dbc.getConnection());

            OracleDataReader reader = comm.ExecuteReader();


            tableListhist.ColumnCount = reader.FieldCount;



           for (int i = 0; i < reader.FieldCount; ++i)
            {
                tableListhist.Columns[i].HeaderText = reader.GetName(i).ToLower();
            }

            //tableListhist.DataMember = _tname;
            tableListhist.DataSource = reader;




            reader.Close();
            tableListhist.ReadOnly = true;


        }
        catch (Exception ex)
        {
            Debug.WriteLine(ex.Message);
        }
        finally
        {
            dbc.close();
        }

但是datagridview是空的:(

1 个答案:

答案 0 :(得分:0)

通常将DataTable或DataSet作为DataSource属性的值传递

DataTable dt = new DataTable();
dt.Load(reader);
tableListhist.DataSource = dt;