I have a control that, after postback, saves the form results back to the database. It fills in the values that need to be saved, iterating through the query. So, for the following SQL statement (greatly simplified for discussion) ...
UPDATE MyTable
SET MyVal1 = @val1,
MyVal2 = @val2
WHERE @id = @id
... it cycles through the request keys:
For Each Key As String In Request.QueryString.Keys
Command.Parameters.AddWithValue("@" & Key, Request.QueryString(Key))
Next
HOWEVER, now I am faced with a situation where, under certain circumstances, some of these variables may not be present in querystring. If I do not pass on val2 in the querystring, I get an error message: System.Data.SqlClient.SqlException: Must declare the scalar value "@val2".
Trying to detect missing value in SQL statement ...
IF @val2 IS NOT NULL
UPDATE MyTable
SET MyVal1 = @val1,
MyVal2 = @val2
WHERE @id = @id
... failed.
? SQL RegEx, , ? , ?
: VB . , .