C# SQL Veritabanı Girilen Veriyi Seçilen İki Tarih Arasında Arama

S

Spectrum Artz

Web | Graphics
Ultra Member
Joined
Jul 31, 2019
Messages
525
Reaction score
111
C# Windows Form ile Sql veritabanı bağlantısı kuran ve Form’ da bulunan TextBox kontrolüne girilen veriyi iki adet DateTimePicker kontrolü ile seçilen tarihler arasında filtreleyerek, filtrelenmiş kayıtları DataGridView içinde görüntüleyen örneğe ait kodlar.
Form Tasarımı:
1575917635437.png

İlk olarak SQL bağlantısı kurabilmek için gerekli Namespace eklenecek.
C#:
using System.Data.SqlClient;

Filtrele Butonu için Kodlar:

C#:
private void btnFiltre_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection("server=.;Initial Catalog=otobus;Integrated Security=SSPI");
            DataTable dt = new DataTable();
            string sql = "SELECT ad,soyad,dtarih,puan FROM musteriler WHERE dtarih BETWEEN @tarih1 and @tarih2 and ad=@aranan";
            SqlDataAdapter da = new SqlDataAdapter(sql, con);
            da.SelectCommand.Parameters.AddWithValue("@tarih1", dateTimePicker1.Value);
            da.SelectCommand.Parameters.AddWithValue("@tarih2", dateTimePicker2.Value);
            da.SelectCommand.Parameters.AddWithValue("@aranan", txtAranan.Text);
            con.Open();
            da.Fill(dt);
            dataGridView1.DataSource = dt;
            con.Close();
        }

Ekran Çıktısı:
1575917688493.png
 
Last edited by a moderator:
SPAM IS FORBIDDEN!
  • SPAMMERS ARE BANNED FROM THE FORUM AND CANNOT USE ANY OF THE CHEATS
  • For example: thanks, thx, very good, asdqwe, working, ty and so on!
  • For example: Writing the same message over and over. thanks, thx and so on!
  • Copying and copying someone else's message is prohibited.
  • It is forbidden to send messages to increase the number of comments on threads that you have no knowledge of.
  • Write your own opinion when commenting!
  • If you see spam message, please let us know with the REPORT button!

Tema düzenleyici

Top Bottom