crymnverla
New Member
i have this code thats trying to insert data in to Access but i get a ASP.NET error: <BR>----------------------------------------------------------------<BR>Syntax error in INSERT INTO statement.<BR>----------------------------------------------------------------<BR>If i debug and print out strSQl and pass it it in to the database i have to delete " for it to run at the end and at the begining ot the string.<BR><BR> Public Sub NewRecord()<BR> Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:inetpubwwwrootGlenviewSysDatabaseGlenSys. mdb"<BR> Dim objConn As New System.Data.OleDb.OleDbConnection(strConnection)<BR> Dim strSQL As String = "INSERT INTO CustomerService (Name, Position, Company, Address, City, State, Zip, Country, Phone, Fax, Email, Information)" & _<BR> "VALUES('" & _Name & "', '" & _Position & "', '" & _Company & "', '" & _Address & "', '" & _City & "', '" & _State & "', '" & _Zip & "', '" & _Country & "', '" & _Phone & "', '" & _Fax & "', '" & _Email & "', '" & _Info & "')"<BR> objConn.Open()<BR> Dim objCommand As New System.Data.OleDb.OleDbCommand(strSQL, objConn)<BR> objCommand.ExecuteNonQuery()<BR> objConn.Close()<BR><BR> End Sub<BR><BR>Is it possible that some of the variables (such as _Name or _Info) have apostrophies in them? If they do, the SQL command will fail. You need to replace all apostrophies with two apostrophies so that the SQL engine knows that it's an apostrophy and not the end of a string.<BR><BR>i.e., Replace( _Name, "'", "''" )Anyone else?There isn't a space on either side of the keyword VALUES. Could this be what is causing the problem? I think I've run into problems with this before.This does not work is it hopeless