Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Aug 2009
    Location
    Indiana
    Posts
    37
    Thanks
    11
    Thanked 1 Time in 1 Post

    Question Incorrect Syntax Error Driving me nuts

    Hi I have the following code:

    Code:
    Sub addCourse()
        processUpload()
        Dim de as DictionaryEntry
        For Each de in hashFields
          response.write(de.key & " - " & de.value & "<br />")
        Next
        Dim strRedirect as String = "courseMan.aspx?msg="
        Dim conCourse as New OleDbConnection(dbCon)
        Dim cmdCourse as OleDbCommand
        Dim strSql as String = "Insert Into courses ("
        Dim strSql2 as String = ") Values ("
        Dim intTime as Integer = cint(hashFields("minute")) * 60
        intTime += cint(hashFields("hour")) * 3600
        Dim intId as Integer
        If Len(hashFields("under")) = 0 Then
          strRedirect &= "1"
          strSql &= "crsUnder, crsSection, crsTitle, crsTime"
          strSql2 &= "0, 1, '" & dbSafe(hashFields("title")) & "', " & intTime
          If Len(hashFields("ceu")) <> 0 Then
            strSql &= ", ceu"
            strSql2 &= ", '" & dbSafe(hashFields("ceu")) & "'"
          End If
          strSql &= ", crsState, crsType"
          If hashFields("tp") = 2 Then
            strSql &= ", crsCity, crsFee, crsDate, avail"
            strSql2 &= ", '" & hashFields("state") & "', 2, '" & dbSafe(hashFields("city")) & "', " & hashFields("fee") & ", #" & hashFields("mo") & "/"
            strSql2 &= hashFields("day") & "/" & hashFields("yr") & "#, 1"
          Else
            strSql &= ", crsFee, avail"
            strSql2 &= ", '" & hashFields("state") & "', 1, " & hashFields("fee") & ", 1"
          End If
        Else
          strRedirect &= "4"
          strSql &= "crsUnder, crsSection, crsTitle, crsTime, crsType"
          strSql2 &= hashFields("under") & ", " & hashFields("sec") & ", '" & dbSafe(hashFields("title")) & "', " & intTime & ", 1"
          If Len(hashFields("ceu")) <> 0 Then
            strSql &= ", ceu"
            strSql2 &= ", '" & dbSafe(hashFields("ceu")) & "'"
          End If
          strSql &= ", crsState, crsFee, avail"
          strSql2 &= ", '" & hashFields("state") & "', 0, 1"
        End If
        strSql &= strSql2 & ")"
    
        conCourse.Open
          cmdCourse = New OleDbCommand(strSql, conCourse)
          cmdCourse.ExecuteNonQuery
          strSql = "Select Max(id) From courses"
          cmdCourse = New OleDbCommand(strSql, conCourse)
          intId = cmdCourse.ExecuteScalar
          If Len(hashFields("under")) = 0 Then
            strSql = "Update courses Set crsUnder = " & intId & " Where id = " & intId
            cmdCourse = New OleDbCommand(strSql, conCourse)
            cmdCourse.ExecuteNonQuery
            If hashFields("tp") = "2" And Len(hashFields("letter")) <> 0 Then
              Directory.CreateDirectory(letterPath & intId)
              File.Copy(tempPath & hashFields("letter"), letterPath & intId & "\" & hashFields("letter"))
              File.Delete(tempPath & hashFields("letter"))
            End If
          End If
        conCourse.Close
        
        Dim objWriter as StreamWriter = File.CreateText(coursePath & intId & ".html")
        objWriter.Write(hashFields("content"))
        objWriter.Close
        
        If hashFields("tp") = "2" Or hashFields("tp") = "1" Then
          buildFromTemplate(wwwPath & "details\" & intId & ".aspx", "details", "description", hashFields("description"))
        End If
        
        If hashFields("tp") = "1" Then
          If Not(File.Exists(wwwPath & "content\online\" & LCase(hashFields("state")) & ".html")) Or Not(File.Exists(wwwPath & "content\online\" & UCase(hashFields("state")) & ".html"))Then
            objWriter = File.CreateText(wwwPath & "content\online\" & LCase(hashFields("state")) & ".html")
            objWriter.Write("")
            objWriter.Close
          End If
        End If
        
        Response.Redirect(strRedirect)
      End Sub 'addCourse
    When I submit data from the form this is the error I receive.

    Incorrect syntax near ','.
    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: Incorrect syntax near ','.

    Source Error:

    Line 186: conCourse.Open
    Line 187: cmdCourse = New OleDbCommand(strSql, conCourse)
    Line 188: cmdCourse.ExecuteNonQuery
    Line 189: strSql = "Select Max(id) From courses"
    Line 190: cmdCourse = New OleDbCommand(strSql, conCourse)

    [OleDbException (0x80040e14): Incorrect syntax near ','.]
    System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +745
    System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +113
    ASP.admin_courseman_aspx.addCourse() in \\xxx\courseMan.aspx:188
    ASP.admin_courseman_aspx.Page_Load(Object sender, EventArgs e) in \\xxx\courseMan.aspx:14
    System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +14
    System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +35
    System.Web.UI.Control.OnLoad(EventArgs e) +99
    System.Web.UI.Control.LoadRecursive() +50
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +627

    Any advice on how to solve this? I can't figure it out...

  • #2
    New Coder
    Join Date
    Aug 2009
    Location
    Indiana
    Posts
    37
    Thanks
    11
    Thanked 1 Time in 1 Post

    Resolved

    solved it, simply replaced the hashFields with Request.Form... hosting company is wacky...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •