The 'Sütun Adı' property on 'Tablo Adı' could not be set to a 'null' value hatası

alattin (16999) 5 yıl önce sordu

C#, Asp.net MVC ile geliştirilen uygulama aşağıdaki hatayı veriyor:

System.Data.ConstraintException
  HResult=0x8013192A
  Message=The 'Sütun Adı' property on 'Tablo Adı' could not be set to a 'null' value. You must set this property to a non-null value of type 'System.Int32'. 
  Source=<Cannot evaluate the exception source>
  StackTrace:
<Cannot evaluate the exception stack trace>

The 'Sütun Adı' property on 'Tablo Adı' could not be set to a 'null' value. You must set this property to a non-null value of type 'System.Int32'.  hatasının çözümü nedir?

Toplam 1 cevap


alattin (16999) 5 yıl önce cevapladı

The 'Sütun Adı' property on 'Tablo Adı' could not be set to a 'null' value. You must set this property to a non-null value of type 'System.Int32'.  hatasının çözümü nedir?

Bu hatanın anlamı 'Tablo Adı' tablosundaki 'Sütun Adı' kolonu Int32 değer alması gerekiyorken NULL değer almış. Yani tablonuzda int türünde veri olması gereken bir sütuna siz veri girmemiş, boş bırakmışsınız. Böylelikle bu sütun NULL değerini almış.

Bu sorun genelde mevcut bir veritabanındaki tabloya yeni bir int türüne sahip sütun eklediğinizde çıkar. Doğal olarak yeni eklenen sütun, tablo içinde veri varsa, null değerini alır.

Çözüm olarak yeni eklediğiniz sütuna 0 verisini ekleyebilirsiniz. Burada amaç sütunu NULL değerinden kurtarmaktır. Elbette siz kendinize uygun olan veriyi yazmalısınız.