How do I set a SqlParameter's value to the equivalent of a SQL INSERT statement's DEFAULT
keyword?
MSDN documentation says to "use null or do not set Value to use the default value for the parameter." However, doing either results in a SqlException complaining that an expected parameter was not supplied. I also tried setting the parameter to DBNull.Value but that results in a complaint about null values not being allowed.
What's the correct way to do this?
-- table schema
CREATE TABLE SomeTable (Field INT NOT NULL DEFAULT(1));
using (var command = this.conn.CreateCommand())
{
command.CommandText = "INSERT [dbo].[SomeTable] ([Field]) VALUES (@p0);";
var param = new SqlParameter();
param.ParameterName = "@p0";
//param.Value = ??;
command.Parameters.Add(param);
command.ExecuteNonQuery();
}