-2

I am saving a photo to another table when saving the form. everything works very well. but the update does not work when updating, so the error is "can not be cast from dbnull to other types"

image

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
  • Just a side comment. Why not do the update first then check if @@rowcount = 0 and if so do the insert. Saves doing the initial exists check, would be faster, as for updates just doing one operation – Ab Bennett Nov 03 '17 at 19:35
  • Don't post images of your code, especially bad cell phone captures. It makes it harder for us to help you, meaning you're less likely to get a good answer. – Joel Coehoorn Nov 03 '17 at 19:46
  • @joel coehoorn Thank you for your suggestion. Unfortunately, I could send it to my computer because there was no internet. I answered my own responsibility below. thank you so much – enver Köseler Nov 03 '17 at 20:02

1 Answers1

0

I wrote the problem I was researching for days, and after 5 minutes, something came to my mind and my problem was resolved. friends who will have the same problem use this rationale

Declare @NMID int
    if exists(Select 1 from Musteriler where MID=@MID)
    BEGIN
        Update Musteriler Set MusteriKategori=@MusteriKategori, AdiSoyadi = @AdiSoyadi, TelefonNo=@TelefonNo, Eposta=@Eposta, Memleketi=@Memleketi, Meslegi=@Meslegi, Adres=@Adres, MusteriHakkindaNot=@MusteriHakkindaNot, Maker=@Maker, Updated=GETDATE()  
        where MID=@MID

        Select @NMID=@MID
    END
    ELSE
    BEGIN
        Insert Into Musteriler(MusteriKategori, AdiSoyadi, TelefonNo, Eposta, Memleketi, Meslegi, Adres, MusteriHakkindaNot, Maker, Updated) values (@MusteriKategori, @AdiSoyadi, @TelefonNo, @Eposta, @Memleketi, @Meslegi, @Adres, @MusteriHakkindaNot, @Maker, GETDATE())
        SELECT  @NMID=SCOPE_IDENTITY();
    END
SELECT @NMID
END
Chris Mack
  • 5,148
  • 2
  • 12
  • 29