PDA

View Full Version : Passing NULL string value in <...METHOD=POST>


RadarBob
08-06-2002, 04:20 PM
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:

<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:
theform.fCitationState.value = "";


BTW, is the above different from
theform.fCitationState.value = null;

glenngv
08-07-2002, 02:45 AM
can you post your asp code?

whammy
08-07-2002, 11:44 PM
In your table design, do you allow nulls in those fields?

RadarBob
08-08-2002, 01:09 PM
Originally posted by whammy
In your table design, do you allow nulls in those fields?
yes, of course.

RadarBob
08-08-2002, 04:09 PM
The page has code like this:

If(Request.Form("fCitationFed") <> "") Then
sCitationFed = Request.Form ("fCitationFed")


I added an "else" piece, basically forcing a default value.

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