I have an application that when I run an update statement, on a given condition a value must be set to null.
I am using StringBuilder to create my sql string and I can't a value to set to null. Given that I've used the DBNull.Value and it's inserting a blank string ("") into the database instead of null can you insert a null value into a database using a stringbuilder and an execute query statement?
Here is what I am using. I have tried just .Append(DBNull.Value) but a query won't execute like that because it doesn't put anything there so the query ends up like
... , [lastRunProcessGUID] = where ... (using Nothing results in the same thing)
With psSql
.Append("update [connection string] ")
.Append("set [Status] = ")
.Append("'" & newStatus & "' ")
If newStatus.Equals("0") Then
.Append(", [lastRunProcessGUID] = ")
.Append("'" & DBNull.Value & "'")
End If
.Append(" where [workItemID] = ")
.Append("'" & workItemID & "' AND")
.Append("' [StepLogID] = ")
.Append("'" & stepLogID & "'")
End With
.Append("'" & DBNull.Value & "'")with.Append("NULL")- no text delimiters - Just explicitly stating the value NULL.