8 Replies - 22462 Views - Last Post: 24 September 2010 - 09:29 AM Rate Topic: -----

#1 eTech1  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 135
  • Joined: 27-August 10

Syntax Error In Insert Into Statement

Posted 23 September 2010 - 12:45 PM

I know this is going to be something stupid but 2 hours is long enough to stair at 10 lines of code and not find the problem. I'm using an access DB.

Here's my code that is throwing the error:
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim cCon As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data source=...")
        cCon.Open()
        Dim cSql As String = "INSERT INTO chatLog(conferenceID,userName,message,time) VALUES(@conferenceID,@userName,@message,Now());"
        Dim cCmd As New OleDbCommand(cSql, cCon)
        cCmd.Parameters.AddWithValue("@conferenceID", Request.QueryString("conferenceID"))
        cCmd.Parameters.AddWithValue("@userName", Session("USER"))
        cCmd.Parameters.AddWithValue("@message", Request.QueryString("sendText"))
        cCmd.ExecuteNonQuery()
        cCon.Close()
    End Sub


If I remove the ExecuteNonquery and replace it with this
        Response.Write(Request.QueryString("conferenceID") + " " + Session("USER")+" "+Request.QueryString("sendText"))


Then it prints out correct values proving that my parameters all have values. I'm just not catching a simple mistake here, I'm sure of it!!

Please let me know what you see or even if you see nothing.

Thanks again.

Is This A Good Question/Topic? 0
  • +

Replies To: Syntax Error In Insert Into Statement

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Syntax Error In Insert Into Statement

Posted 24 September 2010 - 04:29 AM

I would be nice if you told us what error it's throwing and which line of code is throwing the error.
Was This Post Helpful? 0
  • +
  • -

#3 eTech1  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 135
  • Joined: 27-August 10

Re: Syntax Error In Insert Into Statement

Posted 24 September 2010 - 06:18 AM

The error was the title "Syntax Error In Insert Into Statement" and the line is cCmd.ExecuteNonQuery(). Sorry about that.
Was This Post Helpful? 0
  • +
  • -

#4 weedweaver  Icon User is offline

  • New D.I.C Head

Reputation: -1
  • View blog
  • Posts: 42
  • Joined: 01-May 07

Re: Syntax Error In Insert Into Statement

Posted 24 September 2010 - 06:52 AM

Do you have SQL profiler running? If not, get that up and running and you can see exactly the SQL it is generating and debug from there.
Was This Post Helpful? 0
  • +
  • -

#5 eTech1  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 135
  • Joined: 27-August 10

Re: Syntax Error In Insert Into Statement

Posted 24 September 2010 - 07:20 AM

I was curious if something like that existed! Is this built into Visual Web Developer or a standalone program?
Was This Post Helpful? 0
  • +
  • -

#6 eTech1  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 135
  • Joined: 27-August 10

Re: Syntax Error In Insert Into Statement

Posted 24 September 2010 - 08:18 AM

It looks like SQL profiler doesn't work with Access databases(unless i just read up on an older version?). I did find something that I believe will work similarly. ODBC Data Source Administrator is in administrative tools but when I run it it's not creating a log file.
Was This Post Helpful? 0
  • +
  • -

#7 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Syntax Error In Insert Into Statement

Posted 24 September 2010 - 08:28 AM

Change this line...

Dim cSql As String = "INSERT INTO chatLog(conferenceID,userName,message,time) VALUES(@conferenceID,@userName,@message,Now());"



to this..

Dim cSql As String = "INSERT INTO chatLog(conferenceID,userName,message,time) VALUES(?,?,?,Now());"


Was This Post Helpful? 0
  • +
  • -

#8 eTech1  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 135
  • Joined: 27-August 10

Re: Syntax Error In Insert Into Statement

Posted 24 September 2010 - 08:56 AM

Same result, also with a process of elimination I had come up with Now() as my problem entry. I know I've entered the current datetime into an Access DB before with something similar to this but I couldn't find that code. does that need to be converted to a date object somehow or did I just use the wrong function name for Now()?
Was This Post Helpful? 0
  • +
  • -

#9 eTech1  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 135
  • Joined: 27-August 10

Re: Syntax Error In Insert Into Statement

Posted 24 September 2010 - 09:29 AM

Why would I think for a second that time wasn't a keyword. My bad, sorry for wasting your [time].
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1