I had ddl which determine gender and user can donot choose any value from ddl so i tried to check if user didnot select any value from ddl inser null value or any value in database i made that but error apear(Procedure or Function ‘InsertRegisteration’ expects parameter ‘@Gender_Id’, which was not supplied).any one help me
(My Code)
if (DDLGender.SelectedItem.Value[0]!= null )
{
command.Parameters.Add("@Gender_Id",SqlDbType.Int).Value=null;
}
else
{
command.Parameters.Add(Parameter.NewInt("@Gender_Id", DDLGender.SelectedValue));
}
Try this:
Added : Difference between
nullandSystem.DbNull.ValueWell,
nullis not an instance of any type. Rather, it is an invalid reference.However,
System.DbNull.Value, is a valid reference to an instance ofSystem.DbNull(System.DbNullis a singleton andSystem.DbNull.Valuegives you a reference to the single instance of that class) that represents nonexistent* values in the database.*We would normally say
null, but I don’t want to confound the issue.So, there’s a big conceptual difference between the two. The keyword
nullrepresents an invalid reference. The classSystem.DbNullrepresents a nonexistent value in a database field. In general, we should try avoid using the same thing (in this casenull) to represent two very different concepts (in this case an invalid reference versus a nonexistent value in a database field).Keep in mind, this is why a lot of people advocate using the null object pattern in general, which is exactly what
System.DbNullis an example of.