Question : how to insert null value in a table using SQLParameter class

i am working on a windows application made in C# dotnet 2005.
in this i have a form which have a  list which gets filled from another table.
basically i have a column in a table which is forgein key.

now i wrote a update query and i want to insert null if user does not select any item from the list.
and this column is of int type in the database.

and i am using SQLParameter class to add values in update query.

here is a sample code of how i am using SQLParameter class

                SqlParameter SqlParam_GeneralLedgerAccountOID = new SqlParameter();
                SqlParam_GeneralLedgerAccountOID.ParameterName = "@OID";
                SqlParam_GeneralLedgerAccountOID.Value = OID;
                command.Parameters.Add(SqlParam_GeneralLedgerAccountOID);

how can insert null value using  SQLparameter class

Answer : how to insert null value in a table using SQLParameter class

Hello deepakyadav,

Assuming that your column allows NULL values then it would be:

                SqlParam_GeneralLedgerAccountOID.Value = DBNull.Value;

Regards,

TimCottee
Random Solutions  
 
programming4us programming4us