Next code is giving me an exception:
cmd.CommandText = @"insert Table ";
cmd.CommandText += @"(StartTime,
EndTime)
values(@StartTime,
@EndTime)
SELECT CAST(scope_identity() AS int)";
cmd.Parameters.AddWithValue ( "@StartTime", DBNull.Value );
cmd.Parameters.AddWithValue ( "@EndTime", DBNull.Value );
cmd.ExecuteScalar();
The exception I am getting is Must declare '@StartTime' variable
and same thing for @EndTime
. Isn't the DBNull.Value
used for things like this, what am I doing wrong?