I am creating an update query string in Bizagi, that will be passed to SQL Server to be executed.
The update values are taken from a Bizagi form, and may or not be NULL. The string includes boolean, date and string data types. Each field is a variable.
The string works fine if all the fields have a value, but fails if any of them are NULL.
This is how I am building the string:
var cmd = new SqlCommand("UPDATE dbo.SupplierProductionScheduleReplies SET OrderReceived = " + bOrderReceived + ", FactoryReadyDate = '" + IsNull(dFactoryReadyDate, "") + "', MVTPNo = '" + IsNull(sMVTPNo, "") + "', LastUpdated = '" + IsNull(dLastUpdated, "") + "' WHERE id = " + iId);
cmd.Connection = connection;
cmd.ExecuteNonQuery();
connection.Close();
I have tried simplifying the query to one column:
var cmd = new SqlCommand("UPDATE dbo.SupplierProductionScheduleReplies SET FactoryReadyDate = '" + IsNull(dFactoryReadyDate, NULL) + "' WHERE id = " + iId);
but using this the code in Bizagi errors, looking for the variable NULL.
The error message is around the formatting of fields, like the date field, as '""' when trying to enter a NULL entry.
I have tried replicating it in SSMS, but because I am not passing in a string from a 3rd party, I don't know how to replicate what I am trying to send.
The result I am after is an update string that can be passed to SSMS that allows for NULL values for all/some of the variables, except iId.