I want to get specific data from Excel Sheet into winforms TextBoxes using search query. something like this "Search * from [Sheet1] where Staff Number=1234"
i tried this block of code but it's not working. I got an exception every time that says, Connection is not initialized properly.
try{
OleDbConnection con = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;data source=Test.xls;Extended Properties=Excel 8.0;");
con.Open();
OleDbCommand oleDbCommand = new OleDbCommand("SELECT * FROM [Sheet1] where Staff Number=1234");
OleDbDataReader oleDbDataReader = oleDbCommand.ExecuteReader();
TxtDateOfBirth.Text = oleDbDataReader.GetString(1);
TxtName.Text=oleDbDataReader.GetString(2);
.
.
.
.
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
It's a simple form where the user will input the staff number and get the details of the person in relevant text boxes. Most of My Search results get me the solution of showing data into a datagridview but my problem is a bit different, i know i have to use data reader and execute it, but don't know why getting this problem.
Any Guide would be very helpful.