I’ve already added defined the default value ‘default.gif’ to a column of datatype ntext.
then on the aspx page I placed a file upload control and take it’s file name value as a parameter in an INSERT query to the column. what I was trying to do is to be able to point to a specific file when there’s no one uploaded so every item will have a picture even the user didn’t upload one!
what I get is an empty value in the field, not even null and not even an two quotations.
Just blank! I wonder why it doesn’t add the default value!
The default value for a column is only used when an
INSERToperation is performed, and either:VALUESlist is given asDEFAULT, e.g.:INSERT INTO Table1 (FileName,/* other columns */)VALUES(DEFAULT,/* other values */)I’m guessing that whatever your data layer is (you haven’t specified one, that I can see) is incapable of generating the
INSERTstatement in this form.Your code:
You’ll need to add some new code, something like:
Then use that insertStatement variable in the
SqlCommandconstructor – you might want to make adding the@PictureFileNameparameter conditional too, and if this is a performance critical portion of the app, you might want to use a stringbuilder to construct this insert statement, or use string formatting code.