Results 1 to 10 of 10

Thread: passing NULL as parameter to SP

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Location
    india
    Posts
    95

    passing NULL as parameter to SP

    hi


    i using exec SPName 'filterthis',1,NULL in query analyser. it works successfully.

    i m accessing SQL stored proc in my page and i want to pass NULL as parameter from asp.net. but there is no enum for SqlDBtype.null. how can i pass NULL as parameter?

  2. #2
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: passing NULL as parameter to SP

    How about System.DBNull

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2004
    Location
    india
    Posts
    95

    Re: passing NULL as parameter to SP

    Quote Originally Posted by mendhak
    How about System.DBNull

    im trying to pass as "@vsUserID", SqlDbType.Char, 8, System.DBNull

    but its not working and its giving error:

    'DBNull' is a type in 'system' cant be used as expression.

  4. #4
    PowerPoster
    Join Date
    Nov 2001
    Location
    Trying to reach and stay in the cloud
    Posts
    2,089

    Re: passing NULL as parameter to SP

    I guess, its DBNull.value

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: passing NULL as parameter to SP

    You could also try just not setting a value.... by its very nature that would make it NULL.

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  6. #6
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: passing NULL as parameter to SP

    System.Data.SqlTypes.SqlString.Null the value is not important it is used to get/set the .net value type value.... you can SqlString = "sdfgsgdfg" or qlString.Value = "sdgdfgsfgsdfgf" the correct way to get a String is String = SqlString.Value

    p.s. a stored procedure with invalid number of parameters passed in will fail and I'm not sure you can create a parameter object with out setting a value. However if you set the parameters default value to NULL in the sp you can omit that parameter and any other with a default value set.
    Magiaus

    If I helped give me some points.

  7. #7
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: passing NULL as parameter to SP

    the .Value I mean....
    Magiaus

    If I helped give me some points.

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: passing NULL as parameter to SP

    Quote Originally Posted by Magiaus
    System.Data.SqlTypes.SqlString.Null the value is not important it is used to get/set the .net value type value.... you can SqlString = "sdfgsgdfg" or qlString.Value = "sdgdfgsfgsdfgf" the correct way to get a String is String = SqlString.Value

    p.s. a stored procedure with invalid number of parameters passed in will fail and I'm not sure you can create a parameter object with out setting a value. However if you set the parameters default value to NULL in the sp you can omit that parameter and any other with a default value set.
    You most certanly can.... I do it every day....If you create a parameter and don't set the value, and don't have a default value set, the parameter will be NULL. As long as you create it and append it, it won't (shouldn't) give you errors about missing a parameter.

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Frenzied Member Magiaus's Avatar
    Join Date
    Mar 2002
    Location
    swamp land
    Posts
    1,267

    Re: passing NULL as parameter to SP

    Can you post a snippet of how your building the parameter? I don't doubt your right; I just want to see how your doing it. I usually just use null in C#...
    Code:
    SqlParameter param = new SqlParamater("@SeadchName", null);
    and for instance it would bring any names matching search name or everything if null....
    Magiaus

    If I helped give me some points.

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: passing NULL as parameter to SP

    Same as you would if you were setting a value.... just leave off the value part of the CreateParameter.....
    "@vsUserID", SqlDbType.Char, 8 <-- see? Just don't set the value.... create the parameter, just no value.
    instead of
    "@vsUserID", SqlDbType.Char, 8, System.DBNull

    Tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width