0
我想在Windows窗体应用程序的DataGridView中显示Oracle Data,但它只是返回一个灰色的空白视图。我给这家代码当前是:如何在GridView中使用TextBox值在Oracle数据库中搜索数据
string insertquery = "select * from Candidate where CandidateName like '"+ txtBoxSearchData.Text +"%'";
OracleConnection con = new OracleConnection(oradb);
con.Open();
OracleCommand cmd = new OracleCommand();
cmd.Connection = con;
cmd.CommandText = insertquery;
try
{
OracleDataReader reader = cmd.ExecuteReader();
OracleDataAdapter orada = new OracleDataAdapter(cmd);
DataTable dataTable = new DataTable();
orada.Fill(dataTable);
dataTable.Load(reader);
BindingSource bSource = new BindingSource();
bSource.DataSource = dataTable;
dataGridViewSearch.DataSource = bSource;
orada.Update(dataTable);
}
catch(ArgumentException ex)
{
MessageBox.Show("Error: " + ex.Message);
}
catch(OracleException ex1)
{
MessageBox.Show("Error: " + ex1.Message);
}
finally
{
cmd.Dispose();
con.Dispose();
}
}
我肯定我不要求我尝试语句中的所有这些功能,但我也碰到过许多不同的方法来做到这一点 - 我只是包括了所有那些为我的代码实验。连接字符串也是正确的,因为我成功地通过我的应用程序的另一部分中的查询将数据添加到表中。