Single quote error in basic Web Service

Aug 4 2004 9:34 AM
Hi, I tried one of the authors applications here - http://www.c-sharpcorner.com/1/insert_query.asp I changed it around so it would be a simple method in a web service that returns a string if the statement is executed properly. But the problem I seem to be having is using single quotes... I get an error. While I did try using 2 single quotes - it oddly worked and put a single quote into the database. Now this single quote thing is a problem because when I try to extract the data and use it as a parameter in another method, it starts to complain about it... any help would be nice. I must add that this adding of a single quote did work before, no idea what the hell is going on now. If someone could try it and let me know too... thanks. Here is the code below: <%@ WebService Language="C#" class="Reggie" %> using System; using System.Data; using System.Data.OleDb; using System.Web.Services; class Reggie { [WebMethod] public string Adder(string CusID) { string strDSN = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\mdb.mdb"; string strSQL = "INSERT INTO Customers(Name ) VALUES('"+ CusID + "')"; bool ErrorCatch = false; OleDbConnection myConn = new OleDbConnection(strDSN); OleDbCommand myCmd = new OleDbCommand( strSQL, myConn ); try { myConn.Open(); myCmd.ExecuteNonQuery(); } catch (Exception e) { ErrorCatch = true; Console.WriteLine("Sorry, there was an error. Please check back later.", e); } finally { myConn.Close(); } if(ErrorCatch==true) { return ("Error"); } else { return ("Added.");} } }

Answers (1)