McGrath Electronics, Inc. Provides Network Support in Phoenix, AZ
  McGrath Electronics, Inc. Provides Network Design for the 21st Century
Home Products Software Services Support Contact Us  

Function to Parse Strings for SQL Statements (VB ASP ASP.NET)

 

Logoff Screen Saver

Printing Problems

Identifying Memory

Windows Update Problems

Links to Manufacturers

Source Code

 

Valid XHTML 1.0 Strict

The apostrophe ( ' ) sometimes referred to as a single quote can cause SQL statements to fail when posting records to dBase and Paradox tables. If someone's name entered in a text box was Bill O'Rielly, trying to post the text directly to a database using a SQL statement will fail. The reason for the failure is the apostrophe is also used to denote the beginning and end of text in a SQL statement. Adding an additional apostrophe ( '' ) to the name corrects the problem, (i.e. Bill O''Rielly). Since we can not expect the user to know they should enter double quotes instead of the correct spelling of their name in a text field, the best way to fix it is to search the text and add the second apostrophe. The function below is one way of accomplishing this task.

 
This is an example of how I call this function when I am building a SQL statement.
Note the extra space before the double quotes at the end of each line except the last. They are required so the string for the SQL statement is properly formed.