C#.Net ile MonthCalendar nesnesini kullanarak verileri filtremelek.

Merhabalar efendim, bu seferde C#.net de MonthCalendar nesnesiyle tarihe göre filtreleme nasıl yapacağımızı göreceğiz.. Bu uygulama ilk yaptığımız örneğin bir nevi meyvelerinden birtanesi. Sadece kullanının takvim üzerinden seçeceği günü sql cümlemize ekleyip datagridview1 nesnemizi yeniden dolduracağız. c# monthcalendar örneği..

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            gridDoldur("SELECT * FROM TABLO order by ALAN DESC");
        }

        private void gridDoldur(string sqlCumle) {
            string ConStr = "Server=server_adresi; Database=veritabani; uid=kullanici_adi; " +
                            "pwd=sifre;pooling=true; connection lifetime=10; connection timeout=5; packet size=1024;";
            SqlConnection conn = new SqlConnection(ConStr);
            string sql = sqlCumle;
            SqlDataAdapter da = new SqlDataAdapter(sql, conn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dataGridView1.DataSource = ds.Tables[0];
        }

        private void monthCalendar1_DateChanged(object sender, DateRangeEventArgs e)
        {

            string tarih = monthCalendar1.SelectionRange.Start.ToString();
            tarih = tarih.Substring(0, 10);
            gridDoldur("SELECT * FROM TABLO WHERE TARIH = '" + tarih + "' ");
        }

    }
}