Monday, March 26, 2012

Validating Input

Hello,

When I put together an ASP site that requires user input, I take all the input and make them parameterized (@dotnet.itags.org.whatever). When I fill in only some of the text fields (say, 3 out of 5) and click the submit button, I get an error stating that the INSERT statement is incorrect.

I was told that the reason for this is that I'm not validating that these optional text fields do or do not have something typed in them. If nothing has been supplied in them then the SQL parameter in NULL and the INSERT doesn't like it and, errors out.

How would I be able to validate that a text field has had something entered into it or not and, if something has not been entered in, how do I tell it not to include that in the INSERT statement? I'm sure it will need to use an IF statement but I'm not sure on the logic behind it.

Thanks!
Dale


If MyTextBox.Text=String.Empty then
' Do something
End if

You will likely need to either tailor your SQL String, or set the missing parameters to dbNull.Value. Normally, I just use optional parameters on stored procedures, which is lots easier.
Whoa... I didn't follow that.

When I re-read my original message I notice I left out that I'm a newbie to this. It sounds like it's good advise, but could I get a little more detail on this?

Thanks!
Dale

No comments:

Post a Comment