Fill listbox from excel sheet
Hi,
I use this code to fill a listbox from an excel sheet
OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " +
"Data Source=C:\\MyExcel.xls;" +
"Extended Properties=" + (char)34 + "Excel 8.0;HDR=Yes;" + (char)34);
string Statement = ("SELECT * FROM [MatterNumber$] WHERE matter <> '' ");
OleDbCommand cmd = new OleDbCommand(Statement, conn);
try
{
conn.Open();
OleDbDataReader myReader = cmd.ExecuteReader();
while(myReader.Read())
{
listBox1.Items.Add(myReader.GetString(0));
}
}
catch(OleDbException ex)
{
MessageBox.Show(ex.Message);
}
conn.Close();
When i run the code i get the error message "Data type mismatch in criteria expression"
Anybody have an idea what am doing wrong
Thanks!
|