View Single Post
  #8 (permalink)  
Old August 2nd, 2004, 02:19 PM
RPG SEARCH RPG SEARCH is offline
Friend of Wrox
 
Join Date: Apr 2004
Location: Preston, Lancashire, United Kingdom.
Posts: 105
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to RPG SEARCH
Default

Hi there,

I worked out some of the problems with the database and cant get any furture than this.

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 18: dbCommand.Parameters.Add("@CategoryName", OleDbType.VarChar, 15).Value = txtCategoryName.Text
Line 19:
Line 20: dbCommand.ExecuteNonQuery()
Line 21: dbConnection.Close()
Line 22:

the page generates alright but as soon a i click it generates the above.

page code is, left out html for ease, cheers:

<%@ Page Language="VB" Debug="true" %>
<%@ Register TagPrefix="Include" TagName="Header" Src="includes/header.ascx" %>
<%@ Register TagPrefix="Include" TagName="Footer" Src="includes/footer.ascx" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">

    ' This is the code that insert the category name when it is clicked.
    Sub BtnCategoryCreate_Click (sender as object, e as eventargs)

            Dim connectionString as string = "Provider=Microsoft.Jet.OLEDB.4.0; Ole Db Services=-4; Data Source=C:\Inetpub\wwwroot\web sites\database\database.mdb"
            Dim dbConnection As New OleDbConnection(connectionString)
                dbConnection.Open()

            Dim commandString as string = "INSERT INTO Categories (CategoryName)"

            Dim dbCommand as new OleDbCommand(commandString, dbConnection)

            dbCommand.Parameters.Add("@CategoryName", OleDbType.VarChar, 15).Value = txtCategoryName.Text

            dbCommand.ExecuteNonQuery()
            dbConnection.Close()

        End Sub

</script>



David