Link to home
Start Free TrialLog in
Avatar of chrisryhal
chrisryhal

asked on

Using Special Character Strings With SQL And C#

Trying to insert some records with my ASP.NET app and noticed that I can't insert special characters.   An example would be if I inserted "President" into the <TABLE>.Title column it works..............but if I type in "President's" its fails because of the " ' "

I know in VB.NET I used to do a

              strSQLInsert = strSQLInsert & "'" & Trim(txtTitle.Text) & "',"

and thing I remember it working correctly.  Any insight with C# is greatly appreciated.
strSQLInsert = "INSERT INTO <TABLE>(Title,Address,City,State,Description,Type,UserID,Approved) values (";
            strSQLInsert = strSQLInsert + "'" + txtTitle.Text + "',";
            strSQLInsert = strSQLInsert + "'" + txtAddress.Text + "',";
            strSQLInsert = strSQLInsert + "'" + txtCity.Text + "',";
            strSQLInsert = strSQLInsert + "'" + cmbState.SelectedValue + "',";
            strSQLInsert = strSQLInsert + "'" + txtDescription.Text + "',";
            strSQLInsert = strSQLInsert + "'" + cmbDestinationType0.SelectedValue + "',";
            strSQLInsert = strSQLInsert + "'" + siteUser.UserId + "',";
            strSQLInsert = strSQLInsert + "'" + false + "')";

Open in new window

SOLUTION
Avatar of Daniel Van Der Werken
Daniel Van Der Werken
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chrisryhal
chrisryhal

ASKER

I converted my code to accomadate the Params since you guys put the fear of god into me and I appreciate the input and suggestion.   Thanks so much for all your help.
tgerbert:  

Thought you might shed some light on this one if possible

https://www.experts-exchange.com/questions/26091280/Object-must-implement-IConvertible.html