If a form has four input values: textBoxForField1, comboBoxForField2, comboBoxForField3, comboBoxForField4.
Let us say, textBoxForField1 and comboBoxForField2 are required, they have already be checked before writing below SQL statement; comboBoxForField3 and comboBoxForField4 are optional. So I only need to check if comboBoxForField3 and DateTimeForField4 are null for INSERT statement.

So I will write something like below. Not sure if I write syntax correctly, it is just my logic.

Now here is question:
For this question, there are only 2 optional input value (Field3 and Field4 are optional), there are already combination of 4 SQL statement. If three optional fields, then combination of 8 SQL statements; if four optional fields, then combination of 16 SQL statements. Apparently, the way I write is not efficient, there must be an efficient way to write it, how to write it?
Thanks.

Edit: I am actually asking how to write the code for Insert statement in the line OdbcCommand cmd = new OdbcCommand(“INSERT into TableRecord(Field1, Field2, Field3, Field4) Values(………….);”);
Inefficency is not your only issue btw. You are opening your code to so called SQL Injection Attacks. What DB abstraction technology are you using?

Sorry, I am not an IT professional, just trying to build some small application for team use. Don’t even know what DB abstraction technology means. All I know is simple SQL statement.

I am just trying to insert Visual Studio form input data into my own Access database, everything is independent from IT department. In other words, front end application is Visual Studio application; back end database is my own Access file.

source