Anarchosa Posted May 22, 2018 Share Posted May 22, 2018 C# Silme İşlemi System.NullReferenceException: 'Nesne başvurusu bir nesnenin örneğine ayarlanmadı.' con, null idi. hatası alıyorum. Alıntı if (MessageBox.Show("Seçili Ögeyi Silmek İstiyor Musunuz ?", "Dikkat", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { con.Open(); komut.Connection = con; komut.CommandText = "DELETE FROM sistem WHERE Kimlik=@Kimlik"; komut.Parameters.AddWithValue("@Kimlik", dataGridView1.CurrentRow.Cells[0].Value.ToString()); komut.ExecuteNonQuery(); con.Close(); MessageBox.Show("Silme İşlemi Başarılı", "Silindi", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Silme İşlemi İptal Edildi"); } if (MessageBox.Show("Seçili Ögeyi Silmek İstiyor Musunuz ?", "Dikkat", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { con.Open(); komut.Connection = con; komut.CommandText = "DELETE FROM fema WHERE Kimlik=@SNO"; komut.Parameters.AddWithValue("@Kimlik", dataGridView1.CurrentRow.Cells[0].Value.ToString()); komut.ExecuteNonQuery(); con.Close(); MessageBox.Show("Silme İşlemi Başarılı", "Silindi", MessageBoxButtons.OK, MessageBoxIcon.Information); fema(); } else { MessageBox.Show("Silme İşlemi İptal Edildi"); } if (MessageBox.Show("Seçili Ögeyi Silmek İstiyor Musunuz ?", "Dikkat", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { con.Open(); komut.Connection = con; komut.CommandText = "DELETE FROM haluk WHERE Kimlik=@SNO"; komut.Parameters.AddWithValue("@Kimlik", dataGridView1.CurrentRow.Cells[0].Value.ToString()); komut.ExecuteNonQuery(); con.Close(); MessageBox.Show("Silme İşlemi Başarılı", "Silindi", MessageBoxButtons.OK, MessageBoxIcon.Information); haluk(); } else { MessageBox.Show("Silme İşlemi İptal Edildi"); } Quote Link to comment Share on other sites More sharing options...
KintaRo Posted May 22, 2018 Share Posted May 22, 2018 DELETE FROM fema WHERE Kimlik=@SNO demişsin ama SNO değişkenini tanımlamamışsın, ondan olabilir. Quote Link to comment Share on other sites More sharing options...
Anarchosa Posted May 22, 2018 Author Share Posted May 22, 2018 (edited) HATA:System.NullReferenceException: 'Nesne başvurusu bir nesnenin örneğine ayarlanmadı.' con, null idi.Sürekli Patlıyor Bu Konuda Nerde Yanlış Yapıyorum.Database İçindeki Kolon İsmi KimlikProgram İçinde Görünen Kolon İsmi Kimlik Edited May 22, 2018 by Anarchosa Quote Link to comment Share on other sites More sharing options...
SimpsoN_Bart Posted May 22, 2018 Share Posted May 22, 2018 Muhtemelen kopyala yapıştır yaptığın için; if (MessageBox.Show("Seçili Ögeyi Silmek İstiyor Musunuz ?", "Dikkat", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { con.Open(); komut.Connection = con; komut.CommandText = "DELETE FROM haluk WHERE Kimlik=@SNO"; komut.Parameters.AddWithValue("@SNO", dataGridView1.CurrentRow.Cells[0].Value.ToString()); komut.ExecuteNonQuery(); con.Close(); MessageBox.Show("Silme İşlemi Başarılı", "Silindi", MessageBoxButtons.OK, MessageBoxIcon.Information); haluk(); } else { MessageBox.Show("Silme İşlemi İptal Edildi"); } 1 Quote Link to comment Share on other sites More sharing options...
Anarchosa Posted May 22, 2018 Author Share Posted May 22, 2018 SimpsoN_Bart, 2 saat önce yazdı: Muhtemelen kopyala yapıştır yaptığın için; if (MessageBox.Show("Seçili Ögeyi Silmek İstiyor Musunuz ?", "Dikkat", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { con.Open(); komut.Connection = con; komut.CommandText = "DELETE FROM haluk WHERE Kimlik=@SNO"; komut.Parameters.AddWithValue("@SNO", dataGridView1.CurrentRow.Cells[0].Value.ToString()); komut.ExecuteNonQuery(); con.Close(); MessageBox.Show("Silme İşlemi Başarılı", "Silindi", MessageBoxButtons.OK, MessageBoxIcon.Information); haluk(); } else { MessageBox.Show("Silme İşlemi İptal Edildi"); } con.open(); patlıyor hala sorun çözülmedi. Quote Link to comment Share on other sites More sharing options...
SimpsoN_Bart Posted May 23, 2018 Share Posted May 23, 2018 Breakpoint koyup debug et bakalım bide Try cath ekle kodlarını stacktrace de tam olarak ne diyor ? patlıyor diye bir hata yok :) Quote Link to comment Share on other sites More sharing options...
KintaRo Posted May 23, 2018 Share Posted May 23, 2018 bence sen connection dahil kodlarını yapıştır buraya öyle bakalim Quote Link to comment Share on other sites More sharing options...
Editor pairs Posted May 23, 2018 Editor Share Posted May 23, 2018 3 tane ayrı silme kodu yazmış haluk(); Bu methodu satırdan kaldırıp. Simpson ın kodunu tekrar denermisin. Quote Link to comment Share on other sites More sharing options...
Anarchosa Posted May 23, 2018 Author Share Posted May 23, 2018 Ustam sorunu çözdüm sorunu OleDbConnection İçinde Tanımlamadığım için farklı bağlantıyı çağırıyordu. İçinde Tanımladım. Sorun Düzelmedi tabi ikinci hatamda; komut.CommandText = "DELETE FROM haluk WHERE Kimlik=@SNO"; komut.Parameters.AddWithValue("@SNO", dataGridView1.CurrentRow.Cells[0].Value.ToString()); komut.CommandText = "DELETE FROM haluk WHERE Kimlik=@Kimlik"; komut.Parameters.AddWithValue("@Kimlik", dataGridView1.CurrentRow.Cells[0].Value.ToString()); Sorun Çözüldü; pairs, 7 saat önce yazdı: 3 tane ayrı silme kodu yazmış haluk(); Bu methodu satırdan kaldırıp. Simpson ın kodunu tekrar denermisin. Şimdi bunun açıklamasını yapayım database yenilemek için kullanıyorum. 3 veri tabanı var. hangi veri tabanında işlem yapsam comboboxtaki SelectIndex değerine göre haluk sistem fema üç değişkenden birini çağırıyor. Database yenileniyor. Quote Link to comment Share on other sites More sharing options...
hadibeolsun Posted June 22, 2019 Share Posted June 22, 2019 (edited) public Boolean Sil(string ID) { string Sql = "EXECUTE SP_KASA_SIL " + ID; if (HareketiVarmi(KasaKoduAl(ID)) == true) { Mesajlar.Uyari("Hareketi olan Kasayı Silemezsiniz !"); return false; //devamında çalıştırma durdur } try { Dbase.Isle(Sql); return true; } catch (Exception) { return false; } } Boolean Edit = false; Güncelleme veya Kaydet İşlemini Kontrol etmek için boolean tipinde Edit isminde değişken Tanımlıyoruz if (Edit == true) //Açılma işlemi yapılmış ise { if (Mesajlar.Sor("İlgili Kasayı Silmek İstediğinizden Emin Misiniz?") == true) { if (Kasa.Sil(AcilanKasaId)) { Mesajlar.Bilgi("Kasa Başarılı bir şekilde Silinmiştir."); this.Close(); } else { Mesajlar.Hata(); } } else { Mesajlar.Bilgi("Kasa Silme İşlemi İptal Edildi"); } } public string KasaKoduAl(string Id) { try { string Sql = "SELECT top 1 KODU FROM TBL_KASA WHERE ID='" + Id + "'"; return Dbase.SatirCek(Sql)["KODU"].ToString(); } catch (Exception) { return "-1"; } } Boolean HareketiVarmi(string KasaKodu) //Kasayı silmek istediğimizde bir hareketi var mı yok mu kontrol ediyoruz. { string Sql = "SELECT COUNT(*) AS ADET FROM TBL_KASA_HAREKET WHERE KASAKODU='" + KasaKodu + "'"; int Adet = Convert.ToInt32(Dbase.SatirCek(Sql)["ADET"].ToString()); if (Adet > 0) return true; //hareket var demek return false; //hareket yok demek } class Veritabani { Classlar.Mesajlar Mesajlar = new Mesajlar(); public SqlConnection Baglan() { string provider = "Data Source=.\\SQLEXPRESS;Initial Catalog=Desktop_OnMuhasebe;Persist Security Info=True;User ID=sa;Password=1"; SqlConnection conn = new SqlConnection(provider); conn.Open(); return conn; } public DataTable TabloCek(string sql) { DataTable tb = new DataTable(); SqlDataAdapter adap = new SqlDataAdapter(sql, this.Baglan()); adap.Fill(tb); return tb; } public DataRow SatirCek(string sql) { DataRow satir = TabloCek(sql).Rows[0]; return satir; } public Boolean Isle(string sql) { try { SqlCommand islem = new SqlCommand(sql, this.Baglan()); islem.ExecuteNonQuery(); return true; } catch (Exception) { return false; } } } SQL'de Stored Procedure oluşturun Adı SP_KASA_SIL olsun. İçeriği şöyle olsun; CREATE PROC SP_KASA_SIL @ID int AS BEGIN DELETE FROM TBL_KASA WHERE ID=@ID END GO Şuan bir Ön Muhasebe Yazılımı yapmaktayım konuyla alakalı SİLME işleminin kodlarını paylaştım. Edited June 22, 2019 by hadibeolsun Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.