p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.1
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 16th, 2004, 07:05 PM
Registered User
Points: 7, Level: 1
Points: 7, Level: 1 Points: 7, Level: 1 Points: 7, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2004
Location: irving, tx, USA.
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
__________________
evol77
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #2 (permalink)  
Old December 16th, 2004, 07:08 PM
Friend of Wrox
Points: 4,166, Level: 27
Points: 4,166, Level: 27 Points: 4,166, Level: 27 Points: 4,166, Level: 27
Activity: 12%
Activity: 12% Activity: 12% Activity: 12%
 
Join Date: Nov 2003
Location: , NJ, USA.
Posts: 1,328
Thanks: 0
Thanked 1 Time in 1 Post
Default

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #3 (permalink)  
Old December 17th, 2004, 06:15 AM
Friend of Wrox
Points: 386, Level: 6
Points: 386, Level: 6 Points: 386, Level: 6 Points: 386, Level: 6
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: , , Denmark.
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.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 05:01 PM
Syntax error in INSERT INTO statement Stephan BOOK: Beginning JavaScript 16 February 22nd, 2005 01:43 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 01:21 AM
Syntax error in INSERT INTO statement sankar ASP.NET 1.1 9 May 20th, 2004 03:48 PM



All times are GMT -4. The time now is 06:48 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc