473,406 Members | 2,698 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,406 software developers and data experts.

syntax error in INSERT INTO Statement

3
Hi, I have a ploblem with an insert statement using an access database, I have the same code with a sql database which works but it doesn't seem to work on access. Could someone please help.
Expand|Select|Wrap|Line Numbers
  1. For i = 0 To dg.Rows.Count - 1
  2. Main.Command.CommandText = "INSERT INTO Diary (Date1, Time, Appointment) VALUES (?, ?, ?)"
  3. Dim param1 As System.Data.OleDb.OleDbParameter = New System.Data.OleDb.OleDbParameter("Date1", dg(1, i).Value)
  4. Dim param2 As System.Data.OleDb.OleDbParameter = New System.Data.OleDb.OleDbParameter("Time", dg(2, i).Value)
  5. Dim param3 As System.Data.OleDb.OleDbParameter = New System.Data.OleDb.OleDbParameter("Appointment", dg(3, i).Value)
  6.  
  7. Main.Command.Parameters.Add(param1)
  8. Main.Command.Parameters.Add(param2)
  9. Main.Command.Parameters.Add(param3)
  10.  
  11. Try
  12. Main.Command.ExecuteNonQuery()
  13. Catch ex As Exception
  14. MsgBox(ex.Message)
  15. End Try
  16. Main.Command.Parameters.Clear()
I get "syntax error in INSERT INTO Statement" i've tried writing the values directly into the command text and that gives me the same error. Am I missing something totally obvious here?

Thanks in advance.
Sep 26 '09 #1
3 5221
NeoPa
32,556 Expert Mod 16PB
You don't say which version of SQL your "sql database" is. That doesn't help us to help you.

Fundamentally though, you are using some other version of SQL in Access which supports Jet-SQL. Many of these commands and constructs are not supported in Jet-SQL.

Frankly, this doesn't even look like any SQL I've ever seen. You seem to be assigning a set of SQL commands to a string within some sort of code. The only other code I can imagine you using would be VBA and this doesn't look remotely like that either.

Before we can make any sense of this you will need to explain what this is. Both the programming language and the version of SQL.
Sep 26 '09 #2
gilesy
3
Ok well it's oledb 12 not jet, the INSERT statement is taken from the microsoft website which is why i'm confused about it not working. The language is vb.net.

essentially the insert statement should translate into "INSERT INTO table (column name, column name.....) VALUES ('value1', 'value2'......)"

EDIT. Not to worry i fixed it now.
Sep 26 '09 #3
NeoPa
32,556 Expert Mod 16PB
@gilesy
Thanks for letting us know. That's always appreciated :)
Sep 26 '09 #4

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.