How to pass null value to a function in business logical layer?

Last post 04-01-2007 8:18 AM by TATWORTH. 2 replies.

Sort Posts:

  • How to pass null value to a function in business logical layer?

    04-01-2007, 3:40 AM
    • Loading...
    • redmaple
    • Joined on 04-01-2007, 7:29 AM
    • Posts 1

    Hi Guys,

     I meet a problem. I need pass null value to a funtion in business logical layer.

    Public Function JobSearch(ByVal sSkill As String, ByVal iCountryID As Nullable(Of Integer), ByVal iStateId As Nullable(Of Integer)) As JobPostingsDataTable
            Return Adapter.GetDataSearchForJobs(sSkill, iCountryID, iStateId)
    End Function

    sSkill, iCountryID, iStateID are variants in a stored procedure.

    @sSkill varchar(255)

    @iCountryID int=null

    @iStateID int=null

    Please help me, if someone knows how to do it. Thanks a lot.

  • Re: How to pass null value to a function in business logical layer?

    04-01-2007, 8:14 AM
    • Loading...
    • aghausman12
    • Joined on 02-19-2007, 12:55 PM
    • Karachi, Pakistan
    • Posts 400
    redmaple:

    Hi Guys,

     I meet a problem. I need pass null value to a funtion in business logical layer.

     

    well, instead of using nullable I would sugges you to use simple Int. then pass nothing in parameter from calling code. and at the time of attaching param check either specific value is nothing or not. check the following.

    if iStateId <> nothing
    'attach parameter

    end if  

    this will work becuase you already code your sp for optional parameters.

    cheers 

    Dont forget to click "Mark as Answer" on the post that helped you. This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
    http://www.geekswithblogs.net/aghausman
  • Re: How to pass null value to a function in business logical layer?

    04-01-2007, 8:18 AM
    Answer
    • Loading...
    • TATWORTH
    • Joined on 02-04-2003, 8:34 AM
    • England
    • Posts 6,587

    The solution is simple! As they are Ids, the values begin at 1. Just pass a 0 and include the following in your stored procedure:

    if @iCountryId < 1 SET @ICountryId = null

     if @iStateId < 1 SET @iStateId = null

    Don't forget to click "Mark as Answer" on the post that helped you.
    This credits that member, earns you a point and marks your thread as Resolved so we will all know you have been helped.
Page 1 of 1 (3 items)
Microsoft Communities
Page view counter