james james

james james

  • NA
  • 419
  • 29.8k

C# searching a Access Database

Nov 3 2017 10:08 AM
I have a Access database that i want to search by date my code returns nothing, what am I missing?
 
  1. public partial class MainWindow : Window  
  2.     {  
  3.   
  4.   
  5.         public MainWindow()  
  6.         {  
  7.             InitializeComponent();  
  8.             loadgrid();  
  9.             txt_Date.Clear();  
  10.   
  11.         }  
  12.           
  13.         private void loadgrid()  
  14.         {  
  15.             OleDbConnection con = new OleDbConnection();  
  16.             con.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ToString();  
  17.             con.Open();  
  18.             OleDbCommand cmd = new OleDbCommand();  
  19.             cmd.CommandText = "Select * from [Sheet1]";  
  20.             cmd.Connection = con;  
  21.             OleDbDataReader rd = cmd.ExecuteReader();  
  22.             dataGrid.ItemsSource = rd;  
  23.             
  24.         }  
  25.   
  26.   
  27. private void btn_Search_Click(object sender, RoutedEventArgs e)  
  28.         {  
  29.               
  30.             OleDbConnection con = new OleDbConnection();  
  31.             con.ConnectionString = ConfigurationManager.ConnectionStrings["Connection"].ToString();  
  32.             con.Open();  
  33.             OleDbCommand cmd = new OleDbCommand();  
  34.             cmd.CommandText = "Select * from Sheet1 WHERE ToDay like ('" + txt_Date.Text + "%')";  
  35.             cmd.Connection = con;  
  36.             OleDbDataReader rd = cmd.ExecuteReader();  
  37.             dataGrid.ItemsSource = rd;  
  38.   
  39.             loadgrid();  
 

Answers (6)