Hello everyone!
I have an app that connects to Excel file via OpenFileDialog() func., then it takes all worksheets to an array list and add them as combobox items. Next step, my code collects information about column names and add them to new combobox. (till here no problems)
Then there is search process by file → worksheet → column. Problem is, there is some values that when i search them they write "data type mismatch in criteria expression ".
My code:
private void searchbtn_Click(object sender, EventArgs e)
{
try
{
string connStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;";
OleDbConnection conn = new OleDbConnection(connStr);
OleDbDataAdapter da = new OleDbDataAdapter("Select * from [" + testcb.SelectedItem.ToString() + "$] where [" + comboBox1.SelectedItem.ToString() + "] = '" + textBox5.Text + "'", conn);
DataTable dt = new DataTable();
da.Fill(dt);
dataGridView2.DataSource = dt;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}Where "testcb" is worksheet name, combobox1 is column name, textbox5 is my search request.
Thanks a lot!
Sincerely.
Adil Aliyev