Did you mean to write this?
if (!String.IsNullOrWhiteSpace(str))
To check, if the string is
not a null or white space and then execute the command.
Also you should always create parameterized commands, this code is viable and exposed to SQL Injection commands and can cause you data loss. You can read on how to pass parameters, instead of string concatenation on
MSDN[
^].
Edit
I am sorry for getting too late for getting back to you, because I have to face electric supply failure too much here in my country.
Now, since you've provided the code that you're using. You can see there are 2 possible places where this error might generate, the textBox1.Text, and the str. Since that check I provided didn't work, you need to check for the value of textBox1 if that is also not null.
Again, as many have also said... You should try out debugger to see which of these variables is null at the run-time. You can create breakpoints on the lines (I would add that on the function call to see the function executing in front of my sight) and then press F11 to continue executing statements. This way, at every stage, you will be able to see which of the objects are null, and which objects have a value and thus you can fix it.