473,382 Members | 1,204 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Syntax Error in INSERT INTO Statement

Hi friends,
I am facing this error in my vb 6.0 code.

The code is...

Expand|Select|Wrap|Line Numbers
  1. Dim conn As New ADODB.Connection
  2. Dim cmd As New ADODB.Command
  3.  
  4.  
  5. Private Sub cmdOK_Click()
  6.  
  7. conn.ConnectionString = "PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source=F:\VB Progs\Cafe\Cafe.mdb;"
  8.  
  9. conn.Open
  10.  
  11. cmd.ActiveConnection = conn
  12. conn.CursorLocation = adUseClient
  13.  
  14. cmd.CommandText = "Insert into Session (UserId) values ('" & txtUserName.Text & "')"
  15.  
  16. MsgBox cmd.CommandText
  17.  
  18. cmd.Execute
  19.  
  20. conn.Close
  21.  
  22. End Sub
When executed, it gives an error message saying...

Run-time error '-2147217900(80040e14)':
Syntax Error in INSERT INTO Statement

Please help.
Sep 23 '07 #1
9 5819
Killer42
8,435 Expert 8TB
Without knowing more about your table and the contents of the textbox it's hard to say for sure. But perhaps your name field had an apostrophe in it? You know, like "O'Reilly" or something. Since the apostrophe character is used to delimit the field, this might confuse the database engine.
Sep 23 '07 #2
Without knowing more about your table and the contents of the textbox it's hard to say for sure. But perhaps your name field had an apostrophe in it? You know, like "O'Reilly" or something. Since the apostrophe character is used to delimit the field, this might confuse the database engine.
Hi
There is no such problem with my textbox "txtName".
When I display the command text in a msgbox, it shows

Insert into Session(UserId) values('test')

And about the table,
Table name is Session with fields,

SessionID Autonumber
UserID Text 50
UserName Text 50

and so on.
I don't think other fields are relevent here.
I don't know what's wrong.
Sep 23 '07 #3
Killer42
8,435 Expert 8TB
I'm going to refer this to the Access forum, as my SQL is somewhat "rusty". (Just for future reference, this originated in the VB forum.)

The only thing I can think of is that perhaps some other field (such as UserName) is mandatory and the "syntax error" actually means that you left out a required field. I'm sure the SQL experts in the Access forum will have a better idea of what's going on.
Sep 23 '07 #4
Thank you very muchh for your concern.
By the way i have only a SessionID field that is Autonumber
that happens to be required (& Primery Key). All other fields have
no constraints.
Anywayz thank you once again.
hope to get some help from access community as well.
Sep 24 '07 #5
NeoPa
32,556 Expert Mod 16PB
Hi sudhanshu.

Did you get :
Insert into Session(UserId) values('test')
or
Insert into Session (UserId) values ('test')?

Try formulating it as :
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO [Session] ([UserId]) VALUES ('test')
and see what it says.
Please post your results precisely in the post as misquotes can waste a lot of time.
Good luck.
Sep 25 '07 #6
Killer42
8,435 Expert 8TB
Did you get :
Insert into Session(UserId) values('test')
or
Insert into Session (UserId) values ('test')?
So the space is significant, then? I wondered about it, but I'm not that familiar with the INSERT syntax yet.
Sep 25 '07 #7
NeoPa
32,556 Expert Mod 16PB
I'd be surprised if it were, but the results as posted were not as expected and I want to make sure we're not dealing with misinterpretations etc before continuing. So much time is wasted chasing leads that turn out simply to be slapdash posts by the OP. The square brackets ([ & ]) ensure we're not falling over any reserved words.
Sep 25 '07 #8
Hi NeoPa & Killer42
thank you very much both of you. It worked.
Perhaps I have field names which are keywords.
I had no idea abt this.
I dont know how I've been using such fieldnames
before without having a problem.
Anyways thank you once again for your concern.
Sep 26 '07 #9
NeoPa
32,556 Expert Mod 16PB
It may not have been reserved words. Often simply going through the code carefully fixes bugs you don't even notice.
Sep 26 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Gérard Leclercq | last post by:
ACCESS First fields are TEXT, last 2 are Numbers The name of the fields are correct. Dim MyConn Set MyConn=Server.CreateObject("ADODB.Connection") MyConn.Open...
4
by: dcarson | last post by:
I've read about this error in several other discussions, but still can't seem to pinpoint the problem with my code. Everything seemed to be working fine for some time, but it now tends to bomb out...
3
by: William | last post by:
i am using a dataset and a DataAdapter to update a table with the following schema: ResourceID ProjectID LastName FirstName Year Nov Dec Jan
7
by: kosta | last post by:
hello! one of my forms communicates with a database, and is supposed to add a row to a table using an Insert statement... however, I get a 'oledb - syntax error' exception... I have double...
2
by: eric dugal | last post by:
Hi all!! I need your help.... i'm working since 2 hours on a simple insert statement, but couldn't handle it. Here is my code : public int ExecQuery(string SqlString) {
3
by: Neil Zanella | last post by:
Hello, I am trying to execute ADO.NET INSERT statement where one of the fields is coming from a password HTML control. When I access the text with password.Value and print with Response.Write...
3
by: Nathan Sokalski | last post by:
When trying to submit data to an Access database using ASP.NET I recieve the following error: System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41...
5
by: amitbadgi | last post by:
Hi guys, I am getting the following error in teh insert statement , I am converting this asp application to asp.net, here is teh error, Exception Details:...
2
by: RSH | last post by:
I have a rather simple script that transfers data from a SQL server database to an Access database. The procedure is intended to be dynamic so I am basically adding a datarow and then passing the...
6
by: ewpatton | last post by:
Good day, I've been trying to work with SQL and an Access database in order to handle custom user profiles. I haven't had any trouble reading from my database, but inserting new entries into...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.