[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-08-31
5
Medium Priority
?
1,412 Views
Last Modified: 2012-06-21
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">
<html>
      <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

        cnn.Open()
        cmd.ExecuteNonQuery()
        cnn.Close()

        cmd.Dispose()
        cnn.Dispose()
     
     end sub
      
      </script>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>

 <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>
 
 </form>



</body>
</html>
0
Comment
Question by:pigmentarts
  • 4
5 Comments
 
LVL 17

Accepted Solution

by:
AerosSaga earned 2000 total points
ID: 11943014
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.

Regards,

Aeros
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11943049
also in your post the title text box is gone.  You either need it there or to remove title from the insert statement.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11943055
oops I see it disregard that second post
0
 
LVL 12

Author Comment

by:pigmentarts
ID: 11943066
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.
0
 
LVL 17

Expert Comment

by:AerosSaga
ID: 11943085
your very welcome if theres anything else I can do just ask.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question