• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1420
  • Last Modified:

error - Syntax error (missing operator) in query expression 'First Name'????

error and code as follows, need help, thanks

Syntax error (missing operator) in query expression 'First Name'.
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 (missing operator) in query expression 'First Name'.

Source Error:

Line 14:
Line 15:         cnn.Open()
Line 16:         cmd.ExecuteNonQuery()
Line 17:         cnn.Close()
Line 18:

Source File: C:\wwwroot\connectinglondon\test1.aspx    Line: 16

<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.OleDb" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
      <script language="VB" runat="server">
       Sub Submit_Click(Sender as Object, e as EventArgs)
               Dim cnn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & server.mappath("cl.mdb"))
        Dim cmd As New OleDb.OleDbCommand
        cmd.CommandText = "INSERT INTO members (title, first_name, last_name) VALUES (" & title.Value  & ", " & first_name.Value  & ", " & last_name.Value & ")"
        cmd.Connection = cnn


     end sub
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

 <form runat="server">
 <input type="text" ID="title" value="Title" runat="server"><br>
 <input type="text" ID="first_name" value="First Name" runat="server"><br>
 <input type="text" ID="last_name" value="Last Name" runat="server"><br>
 <input type="submit" OnServerClick="Submit_Click" value="Submit" runat="server"><br>

  • 4
1 Solution
should be:

  cmd.CommandText = "INSERT INTO members (title, first_name, last_name) VALUES ('" & title.Value  & "', '" & first_name.Value  & "', '" & last_name.Value & "')"

You forgot the single quote ' at the beginning and end of each field your entering.  This is required because its a text or memo field in your database.


also in your post the title text box is gone.  You either need it there or to remove title from the insert statement.
oops I see it disregard that second post
pigmentartsAuthor Commented:
it is alway something simple, thank you, will have to start and learn asp.net as i may need to start to use it a lot more now. but anyway in the mean time thank for you help again.
your very welcome if theres anything else I can do just ask.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now