Stored procedure doesn't allow null parameters even the parameter represent accept nulls?

前端 未结 2 1262
生来不讨喜
生来不讨喜 2021-01-14 14:57

I saw many questions on stack overflow, non of them touched my own problem

procedure or function expects parameter which was not supplied

相关标签:
2条回答
  • 2021-01-14 15:39

    I just found that I can set default values for the parameter in the stored procedure:

    ALTER proc [dbo].[spAddCustomer]
    @cuName varchar(50)=null,
    @cuAddress varchar(50)=null,
    @cuMobile varchar(50)= null,
    @cuImage image= null,
    @cityId int= null,
    @exist int output
    

    And this solved my problem! This is helpful specifically with null images from the PictureBox, since I have a helper method that checks for empty strings.

    0 讨论(0)
  • 2021-01-14 15:39

    You need to check your input for null and use DBNull.Value when you creating the parameters. If you pass just null as a parameter - ADO.Net will ignore that.

    EDIT:

    You can add that check into your custom method DataAccessLayer.CreateParameter()

    0 讨论(0)
提交回复
热议问题