Bu yazımızda C# Sql Server veritabanı bağlantısı oluşturarak kayıtların Textbox‘ larda görüntülenmesini ve İlk Kayıt, Son Kayıt,Önceki Kayıt, Sonraki Kayıt butonlarını kullanarak kayıtlar arasında gezinti yapmayı sağlayan bir örnek gerçekleştireceğiz.
Form tasarımı yukarıdaki şekilde olacaktır. Kullanacağımız veritabanı ismi “okul“, tablo ismide “ogrenci” olacak.
Kodlarımıza geçelim.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Data.SqlClient; namespace vtilk_sonraki { public partial class Form1 : Form { public Form1() { InitializeComponent(); } SqlDataAdapter da; DataSet ds; int i = 0; SqlConnection conn; private void Form1_Load(object sender, EventArgs e) //Form Yüklendiğinde ilk kayıt { conn = new SqlConnection("server =.; Initial Catalog = okul; Integrated Security = SSPI"); conn.Open(); da = new SqlDataAdapter("select * from ogrenci", conn); ds = new DataSet(); da.Fill(ds, "ogrenci"); textBox1.Text = ds.Tables[0].Rows[i]["ogrenci_no"].ToString(); textBox2.Text = ds.Tables[0].Rows[i]["ogrenci_ad"].ToString(); textBox3.Text = ds.Tables[0].Rows[i]["ogrenci_soyad"].ToString(); textBox4.Text = ds.Tables[0].Rows[i]["ogrenci_sehir"].ToString(); } private void button3_Click(object sender, EventArgs e) //Sonraki Kayıt { if (i < ds.Tables[0].Rows.Count - 1) { i++; textBox1.Text = ds.Tables[0].Rows[i]["ogrenci_no"].ToString(); textBox2.Text = ds.Tables[0].Rows[i]["ogrenci_ad"].ToString(); textBox3.Text = ds.Tables[0].Rows[i]["ogrenci_soyad"].ToString(); textBox4.Text = ds.Tables[0].Rows[i]["ogrenci_sehir"].ToString(); } else { } } private void button2_Click(object sender, EventArgs e) //Önceki Kayıt { if (i == ds.Tables[0].Rows.Count - 1 || i != 0) { i--; textBox1.Text = ds.Tables[0].Rows[i]["ogrenci_no"].ToString(); textBox2.Text = ds.Tables[0].Rows[i]["ogrenci_ad"].ToString(); textBox3.Text = ds.Tables[0].Rows[i]["ogrenci_soyad"].ToString(); textBox4.Text = ds.Tables[0].Rows[i]["ogrenci_sehir"].ToString(); } else { } } private void button1_Click(object sender, EventArgs e)//İlk Kayıt { if (ds.Tables[0].Rows.Count > 0) { i = 0; textBox1.Text = ds.Tables[0].Rows[i]["ogrenci_no"].ToString(); textBox2.Text = ds.Tables[0].Rows[i]["ogrenci_ad"].ToString(); textBox3.Text = ds.Tables[0].Rows[i]["ogrenci_soyad"].ToString(); textBox4.Text = ds.Tables[0].Rows[i]["ogrenci_sehir"].ToString(); } } private void button4_Click(object sender, EventArgs e)//Son Kayıt { i = ds.Tables[0].Rows.Count - 1; textBox1.Text = ds.Tables[0].Rows[i]["ogrenci_no"].ToString(); textBox2.Text = ds.Tables[0].Rows[i]["ogrenci_ad"].ToString(); textBox3.Text = ds.Tables[0].Rows[i]["ogrenci_soyad"].ToString(); textBox4.Text = ds.Tables[0].Rows[i]["ogrenci_sehir"].ToString(); } } } |
SELECT TOP 1 * FROM EGITIM_PLANI where EGITIM_SOZLESME_TARIHI >= ” + tarih+” ORDER BY ID DESC ” bu şekil denedim. ama olmadı.
hocam tablodaki son satırdaki tarihi bugünün tarihinden küçük ya da eşitse nasıl getir nasıl yaparım.
Sql tarih ve zaman fonksiyonlari konusunu inceleyebilirsiniz.
http://www.yazilimkodlama.com/sql-server-2/sql-tarih-ve-saat-fonksiyonlari/
usta baktım ama yapamadım. SELECT *FROM EGITIM_PLANI GETDATE dedim tüm tarihleri getirdi. Bu fonksiyonları nasıl kullanacağımı bilmiyorum.