我尝试从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是空的:(
答案 0 :(得分:0)
通常将DataTable或DataSet作为DataSource属性的值传递
DataTable dt = new DataTable();
dt.Load(reader);
tableListhist.DataSource = dt;