ISNULL('" + newimage + "', NULL)
makes no sense -you're always seeing if a string constant is NULL
which is never true.
I suspect you want:
"UPDATE News SET postimage = " + newImage == null ? "null" : "'" + newimage + "'," ...
however for several reasons, you should be using parameters:
String query = "UPDATE News SET postimage = @postImage, Image = @Image WHERE id=@id";
SqlCommand myCommand = new SqlCommand(query, myConnection);
myCommand.Parameters.AddWithValue("@postImage",postImage ?? DBNull.Value);
myCommand.Parameters.AddWithValue("@Image",Image ?? DBNull.Value);
myCommand.Parameters.AddWithValue("@id",id);
myCommand.ExecuteNonQuery();
myConnection.Close();
Notice that if postImage
or Image
are null
that DBNull.Value
is used instead of null
.