
Merhaba arkadaşlar. Bu makalemizde metotlarla nasıl kayıt güncellenir onu öğreneceğiz.
datab.cs
public int ogrencikaydiguncelle(double tc, int no, string Ad, string soyad, DateTime dtarihi, int dyeri, int ilce, int bolum) { komut = new SqlCommand(); komut.CommandText = "update ogrenciler set ogrencino=@no,Ad=@ad,soyad=@soyad,dtarihi=@dtarihi,dyeri=@dyeri,ilce=@ilce,bolum=@bolu m where tc=@tc"; komut.Parameters.Add("@tc", SqlDbType.BigInt).Value = tc; komut.Parameters.Add("@no", SqlDbType.Int).Value = no; komut.Parameters.Add("@ad", SqlDbType.VarChar).Value = Ad; komut.Parameters.Add("@soyad", SqlDbType.VarChar).Value = soyad; komut.Parameters.Add("@dtarihi", SqlDbType.DateTime).Value = dtarihi; komut.Parameters.Add("@dyeri", SqlDbType.Int).Value = dyeri; komut.Parameters.Add("@ilce", SqlDbType.Int).Value = ilce; komut.Parameters.Add("@bolum", SqlDbType.Int).Value = bolum; komut.Connection = baglan;} int sonuc = (int)komut.ExecuteNonQuery(); return sonuc;
Form sayfamız
double tc = 0; int no = 0; if (txttc.Text != "") tc = Convert.ToDouble(txttc.Text); if (txtno.Text != "") no = Convert.ToInt32(txtno.Text); datab vt=new datab(); if(MessageBox.Show("Güncelleme Yapmak istediğinizden emin misiniz","Güncelleme",MessageBoxButtons.YesNo)==DialogResult.Yes) { int sonuc= vt.ogrencikaydiguncelle(tc, no, txtad.Text, txtsoyad.Text,dateTimePicker1.Value, Convert.ToInt32(cbsehir.SelectedValue), Convert.ToInt32(cbilce.SelectedValue), Convert.ToInt32(cbbolum.SelectedValue)); if (sonuc >0) MessageBox.Show("Güncelleme Başarılı"); else MessageBox.Show("Güncelleme Başarısız"); }