我正在努力使我的dataGrid viev查询结果。与数据库的连接很好。以下是我的代码示例:
using (OracleConnection conn = new OracleConnection())
{
conn.ConnectionString = "properConnectionString"
conn.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandText = "select * FROM WORKERS";
cmd.CommandType = CommandType.Text;
OracleDataReader dr = cmd.ExecuteReader();
using (OracleDataAdapter orclDataAdapter = new OracleDataAdapter(cmd))
{
DataTable dt = new DataTable();
orclDataAdapter.Fill(dt);
dataGridView1.DataSource = dt;
}
}
答案 0 :(得分:0)
假设您对Oracle数据库的调用实际上是在返回数据,那么您将错过gridview上的数据绑定语句。加上这个:
dataGridView1.DataBind();
将其放在dataGridView1.DataSource = dt;
代码行之后。