Re: Syntax error in INSERT INTO statement.

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: William \(Bill\) Vaughn (billvaRemoveThis_at_nwlink.com)
Date: 04/02/04


Date: Fri, 2 Apr 2004 11:16:00 -0800

It looks like you're trying to concatenate fields together. This should be
done using an & operator instead of a "+" operator . However, this is not a
good idea. I suggest you use a Command and a Parameters collection to
execute this INSERT. This will eliminate a number of potential issues (one
of which you might have already encountered). More importantly, it will help
prevent SQL injection attacks.

Unfortunately, you're using OleDb which means you can't simply turn on the
Profiler and see what's getting sent to the server for processing.

In any case I also suggest you add a Try/Catch block to the code to trap the
exceptions--this way you can tell what's really going on.

-- 
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
"Jasima DJ" <dakiddgal@hotmail.com> wrote in message
news:%23IvgkVOGEHA.3080@tk2msftngp13.phx.gbl...
> I wrote the following code for my submit button...
>
> Private Sub tb_submit_Click(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles tb_submit.Click
>         Dim strSQL As String = _
>         "INSERT INTO Members
> (userId,password,verify,email,country,addess) VALUES('" + tb_userId.Text
> + "', '" + tb_password.Text + "', '" + tb_verify.Text + "', '" +
> tb_email.Text + "', '" + tb_country.Text + "', '" + tb_address.Text +
> "')"
>         OleDbConnection1.Open()
>         Dim cmd As New OleDbCommand(strSQL, OleDbConnection1)
>         cmd.ExecuteNonQuery()
>         OleDbConnection1.Close()
>     End Sub
> ===========================================================
>
> But i keep getting the following error.....I cant seem to fix...can you
> elp me fix it? plzzz....
>
> Syntax error in INSERT INTO statement.
> Description: An unhandled exception occurred during the execution of the
> current web request. Please review the stack trace for more information
> about the error and where it originated in the code.
>
> Exception Details: System.Data.OleDb.OleDbException: Syntax error in
> INSERT INTO statement.
>
> Source Error:
>
>
> Line 53:         OleDbConnection1.Open()
> Line 54:         Dim cmd As New OleDbCommand(strSQL, OleDbConnection1)
> Line 55:         cmd.ExecuteNonQuery()
> Line 56:         OleDbConnection1.Close()
> Line 57:     End Sub
>
>
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!


Relevant Pages

  • Re: Need help with a question.
    ... When I rapped the code into a Sub I ... syntax error at test.pl line 7, ... If you use GNUish indenting, and such a large indent, you'll quickly run ... We do not stop playing because we grow old; ...
    (comp.lang.perl.misc)
  • RE: Compile error
    ... with Compile error and Syntax error. ... necessary continuation character. ... Sub startFlashing() ... Application.OnTime nextSecond, "flashCell",, False ...
    (microsoft.public.excel.programming)
  • Re: Need help with a question.
    ... When I rapped the code into a Sub I ... syntax error at test.pl line 7, ... I feel really dumb because it took me 5 minutes to figure out. ... Perl is case sensitive. ...
    (comp.lang.perl.misc)
  • Re: Strange syntax error
    ... I get a syntax error I can't explain. ... sub openFile() ... Removing or commenting the openFile sub. ... the Switch module uses a source filter to do its thing. ...
    (comp.lang.perl.misc)
  • Re: C# / SQL Related - whats wrong with this Insert Into syntax?
    ... Strange little problem here... ... I'm getting a "Syntax error in Insert Into statement" when it ... tries to execute the SQL. ... execute it using the MS Access query engine, ...
    (microsoft.public.dotnet.languages.csharp)