I am using new C# 6.0 features String Interpolation for generating SQL statements.
$@"INSERT INTO [dbo].[TableName]([Column1], [Column2]) Values({item.property1}, {item.property2})";
If properties are null then generated SQL is the following
INSERT INTO [dbo].[TableName]([Column1], [Column2]) Values(,)
And this cause an error. (Incorrect SQL).
I need Null instead of empty spaces. Can i somehow achieve this ?
Values(@param1, @param2){item.property1 ?? "Null"}SqlParameter.Value = (object) object ?? DBNull.Valuewill do the Right Thing.