Try this code:
SqlParameter unitsParam = command.Parameters.AddWithValue("@units", units);
if (units == null)
{
unitsParam.Value = DBNull.Value;
}
And you must check all other parameters for null value. If it null you must pass DBNull.Value
value.
More Related Contents:
- How can I catch UniqueKey Violation exceptions with EF6 and SQL Server?
- How can I round a value in SQL
- How do I update a value in C# and SQL Server? [closed]
- Connect to client’s SQL Server [closed]
- How to pass table value parameters to stored procedure from .net code
- Insert 2 million rows into SQL Server quickly
- Execute Insert command and return inserted Id in Sql
- Best practices for exception management in Java or C# [closed]
- C# Equivalent of SQL Server DataTypes
- Adding multiple parameterized variables to a database in c#
- SQL command INSERT is working but the data not appear in table
- Return value from SQL Server Insert command using c#
- How can I insert 10 million records in the shortest time possible?
- How to pass sqlparameter to IN()? [duplicate]
- How to connect to database from Unity
- How to insert a data table into SQL Server database table?
- Connection timeout for SQL server
- Calculated column in EF Code First
- MultipleActiveResultSets=True or multiple connections?
- Is this a bad practice to catch a non-specific exception such as System.Exception? Why?
- Excel error HRESULT: 0x800A03EC while trying to get range with cell’s name
- Generate class from database table
- Show line number in exception handling
- What is passing parameters to SQL and why do I need it?
- Why Create Custom Exceptions? [closed]
- How can I set up .NET UnhandledException handling in a Windows service?
- How do I calculate the equivalent to SQL Server (hashbytes(‘SHA1’,[ColumnName])) in C#?
- How to retrieve binary image from database using C# in ASP.NET
- Use SQL Server time datatype in C#.NET application?
- Is SqlConnection.Close() need inside a Using statement?