Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
|
ASP.NET 1.1 As of 10/6/2005, this forum is locked as part of the reorganization described here: http://p2p.wrox.com/topic.asp?TOPIC_ID=35394. No posts have been deleted. Open ongoing discussions from the last week have been moved to either ASP.NET 1.0 and 1.1 Beginners http://p2p.wrox.com/asp-net-1-0-1-1-basics-60/ or ASP.NET 1.0 and 1.1 Professional. http://p2p.wrox.com/forum.asp?FORUM_ID=50. See my sticky post inside for more.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.1 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 16th, 2004, 07:05 PM
Registered User
 
Join Date: Dec 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Syntax error in INSERT INTO statement

I am new to the programming world. Can someone please help me. I keep getting error during a INSERT statement.
Error Msg
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.

Below is my code... Please assist.

<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    ' Insert page code here
    '
    Dim myConnection as OleDbConnection
    Dim strConnectionString as String = "Provider=Microsoft.Jet.OleDB.4.0;Data Source = C:\Documents and Settings\slalani\Desktop\pubs.mdb"

    Sub Page_Load(send As System.Object, e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then
        GetConnection()
        End If
    End Sub

    sub AddUser(ByVal sender as System.Object, ByVal e as System.EventArgs)
        dim intRecordAffected as Integer
        GetConnection()

        Dim strSql as String = "INSERT INTO users([username],[password]) values('" & _
                    uname.Text & "','" & _
                    password.Text & "')"

        Dim myCommand as New OleDbCommand(strSQL, myConnection)
        ''Dim txtRecAff
        ''Dim intRecordAffected

        ''intRecordAffected = myCommand.ExecuteNonQuery()

        ''txtRecAff = intRecordsAffected & " record added successfully."

        ClearForm()
    End Sub

    sub GetConnection()
        myConnection = New OleDbConnection(strConnectionString)
        myConnection.Open
    End Sub

    Sub ClearForm()
        uname.Text = ""
        password.Text = ""
    End Sub

    Sub addBtn_Click(sender As Object, e As EventArgs)
        ''AddUser(ByVal sender as System.Object, ByVal e as System.EventArgs)
        dim intRecordAffected as Integer
        GetConnection()

        Dim strSql as String = "INSERT INTO users(username,password) values('" & _
                    uname.Text & "','" & _
                    password.Text & "')"

        Dim myCommand as New OleDbCommand(strSQL, myConnection)
        ''Dim txtRecAff
        ''Dim intRecordAffected

        intRecordAffected = myCommand.ExecuteNonQuery()

        ''txtRecAff = intRecordsAffected & " record added successfully."

        ClearForm()
    End Sub


evol77
 
Old December 16th, 2004, 07:08 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,348
Thanks: 0
Thanked 5 Times in 5 Posts
Default

Can you post what the value of strSql before you execute it? That would help in determining the error.

 
Old December 17th, 2004, 06:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

My guess is that it's this line:
Code:
Dim strSql as String = "INSERT INTO users(username,password) values[...]
You need to change it to:
Code:
Dim strSql as String = "INSERT INTO users([username],[password]) values[...]
as at least password is a reserved word.






Similar Threads
Thread Thread Starter Forum Replies Last Post
NEED HELP INSERT INTO statement syntax error koco ASP.NET 1.0 and 1.1 Basics 6 June 2nd, 2006 04:01 PM
Syntax error in INSERT INTO statement mega ASP.NET 1.0 and 1.1 Basics 3 January 12th, 2005 04:30 PM
Syntax error in INSERT INTO statement. askaggs Classic ASP Databases 5 June 10th, 2004 12:21 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.