I'm trying to compare a date obtained from maskedTextBox accepting short date, with a date from an excel sheet.
I need to select those rows from excel file that are equal with the date from the maskedTextBox and display them in datagridview.
The problem is that i don't get any results and compiling the code gives no errors.
My code :

      private void button13_Click(object sender, EventArgs e)

            OleDbConnection conn = new OleDbConnection();
            conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\alekan\Desktop\alm2.xlsx" + @";Extended Properties=""Excel 12.0 Xml;HDR=YES;ImportMixedTypes=Text;TypeGuessRows=0""";
            OleDbCommand command = new OleDbCommand("SELECT txt" + " " + "FROM [sheet2$] WHERE HHMM = '"+ maskedTextBox1.Text+"'", conn);

            DataSet dstxt = new DataSet();
            OleDbDataAdapter adapter = new OleDbDataAdapter(command);
            dataGridView1.DataSource = dstxt.Tables[0];

p.s. txt and HHMM is named columns
any help is GREATLY apreciated!!!!!

Use @parameterized sql statement and that want you can compare data without formating data into string.


string sql = "select txt from [Sheet2$] where HHMM=@dateParam";
OleDbCommand command = new OleDbCommand(sql,conn);