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();
}
}
我肯定我不要求我嘗試語句中的所有這些功能,但我也碰到過許多不同的方法來做到這一點 - 我只是包括了所有那些爲我的代碼實驗。連接字符串也是正確的,因爲我成功地通過我的應用程序的另一部分中的查詢將數據添加到表中。