Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Passing NULL string value in <...METHOD=POST>

    All;
    I am stuffing the values from the Request.form collection into a MS SQL server 7 database via a stored procedure.

    This is the error I'm getting:
    ----------------------------------------------------------

    Database Error(s) encountered executing:

    ----------------------------

    Native Error = 201 SQLState = 42000 Error# = -2147217904
    Error description = Procedure 'up_scDBAdd' expects parameter '@CitationFed', which was not supplied.
    Error source = Microsoft OLE DB Provider for SQL Server
    ----------------------------------------------------------
    However, the process is working when the field has some text; but not when I've set it to null. An empty string is valid under certain conditions (which I'm checking for in the usual form validation prior to SUBMITting).

    My question is: "Can I pass a string that is empty? If so, how?" This is distinctly different from passing a string with one (or more) blank characters. I do not want to use blanks in the database field when I mean "empty".

    NOTE: code snippets are in Javascript

    Here's the form object:
    Code:
       <td colspan=4>
          <span  id="StateCitation" style="visibility:hidden;">
             <b>State Citation: </b>
             <input type="text" name="fCitationState" size=50 value = "">
          </span>
       </td>

    Here is how I set it's value to empty:
    Code:
    theform.fCitationState.value = "";
    BTW, is the above different from
    Code:
    theform.fCitationState.value = null;

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,033
    Thanks
    0
    Thanked 248 Times in 245 Posts
    can you post your asp code?

  • #3
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In your table design, do you allow nulls in those fields?
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by whammy
    In your table design, do you allow nulls in those fields?
    yes, of course.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Round Rock, Texas
    Posts
    443
    Thanks
    0
    Thanked 0 Times in 0 Posts

    I solved the problem

    The page has code like this:
    Code:
        
    If(Request.Form("fCitationFed") <> "") Then 
       sCitationFed = Request.Form ("fCitationFed")
    I added an "else" piece, basically forcing a default value.
    Code:
    If(Request.Form("fCitationFed") <> "") Then 
    sCitationFed = Request.Form ("fCitationFed") 
    else sCitationFed = null
    Apparently, it was not good enough to set the html form field to empty (fCitationFed = ""). Given the original code above the server-side variables are not explicitly set to null - and that makes all the difference. In other words: just because ("fCitationFed") <> "" is true, does not mean ("fCitationFed") == "". Odd, but that's how it seems to be working.

    Perhaps significantly, when these variables (sCitationFed, etc.) are first declared, they are not initialized. I hate having to work with unprofessional, lazy programmers' code!

    Anyway, now, when the command object parameter is built from these variables (sCitationFed, etc.) the parameter exists and has a value of NULL - which properly ends up in the database as NULL
    Last edited by RadarBob; 08-08-2002 at 04:14 PM.


  •  

    Posting Permissions

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