<p>I was previously taught today how to set parameters in a SQL query in .NET in this answer (<a href="https://stackoverflow.com/questions/169359/improving-code-readability-for-sql-commands#169369">click</a>).</p>

<p>Using parameters with values are fine, but when I try to set a field in the database to null I'm unsuccessful. Either the method thinks I am not setting a valid parameter or not specifying a parameter.</p>

<p>e.g.</p>

<pre><code>Dim dc As New SqlCommand("UPDATE Activities SET [Limit] = @Limit WHERE [Activity] = @Activity", cn)

If actLimit.ToLower() = "unlimited" Then
    ' It's not nulling :(
    dc.Parameters.Add(New SqlParameter("Limit", Nothing))
Else
    dc.Parameters.Add(New SqlParameter("Limit", ProtectAgainstXSS(actLimit)))
End If
</code></pre>

<p>Is there something I'm missing? Am I doing it wrong?</p>

Try setting it to
```
DbNull.Value
```
.