DEFAULT value in SqlParameter

J

Janaka

I'd like to submit the default value of a SQL column as the value to send in
my parameter. I know you can use DBNull.Value to enter NULLs. Is there a
way to enter the DEFAULT value?

i.e. in sql it would look something like UPDATE MyTable SET MyColumn =
DEFAULT

in .NET I want to write something like

SqlParameter myParam = new SqlParameter("@MyColumn", SqlDBType.Varchar, 20);
myParam.Value = Default.value;
 
P

Paul Clement

¤ I'd like to submit the default value of a SQL column as the value to send in
¤ my parameter. I know you can use DBNull.Value to enter NULLs. Is there a
¤ way to enter the DEFAULT value?
¤
¤ i.e. in sql it would look something like UPDATE MyTable SET MyColumn =
¤ DEFAULT
¤
¤ in .NET I want to write something like
¤
¤ SqlParameter myParam = new SqlParameter("@MyColumn", SqlDBType.Varchar, 20);
¤ myParam.Value = Default.value;
¤

Can't you just set the default value for the column at the database level and omit the parameter
from your update query?


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
P

Paul Clement

¤ Unfortuanately no. It is an optional field and may have user input or it
¤ may not.
¤

I don't think I understand your reply. If you're using a default value when the field is not
specified then what different does it make whether you specify it at the query level, or the
database level?


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top