Perform a SELECT through C # to an Access database

1
private void button1_Click(object sender, EventArgs e)
{
    OleDbConnection Con = new OleDbConnection();
    Con.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='|DataDirectory|\CALL_CENTER.accdb';Persist Security Info=True";


    try
      {
           Con.Open();
           OleDbCommand Cmm = new OleDbCommand();

           Cmm.CommandText = "SELECT Cliente, DATA_AGENDA FROM Agendamento WHERE Cliente LIKE  '%"+textBox1.Text+"%' AND DATA_AGENDA BETWEEN '"+dateTimePicker1.Value+"' AND DATA_AGENDA '"+dateTimePicker2.Value+"' ";
           Cmm.CommandType = CommandType.Text;
           Cmm.Connection = Con;

           OleDbDataReader DR;
           DR = Cmm.ExecuteReader();

           listBox1.Items.Clear();
           while (DR.Read())
           {
               listBox1.Items.Add(DR.GetString(0) + " / " + DR.GetDateTime(1));
           }

           Con.Close();

      }
      catch (Exception)
      {
           MessageBox.Show("impossível localizar registro! Verifique o código digitado");
      }
}
    
asked by anonymous 14.05.2016 / 02:46

0 answers