473,395 Members | 1,383 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,395 software developers and data experts.

INSERT - SQL. Add Record. Problem. Need Urgent Help. Thank You.

Hello,

I need to add a new record to an ACCESS database.

I get the error: Syntax error in INSERT INTO statement.

I have no idea what am I doing wrong. This is my code:

' Set Connection
Dim connectionString As String = AppSettings("connectionString")
Dim dbConnection As IDbConnection = New
OleDbConnection(connectionString)

' Set Query
Dim queryString As String = "INSERT INTO t_news (title_pt-PT,
title_en-GB, text_pt-PT, text_en-GB, publication_date) VALUES
(@title_pt-PT, @title_en-GB, @text_pt-PT, @text_en-GB,
@publication_date)"

Dim dbCommand As IDbCommand = New OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

' Add Parameters
With dbCommand.Parameters
.Add(New OleDbParameter("@title_pt-PT", "sample"))
.Add(New OleDbParameter("@title_en-GB", "sample"))
.Add(New OleDbParameter("@text_pt-PT", "sample"))
.Add(New OleDbParameter("@text_en-GB", "sample"))
.Add(New OleDbParameter("@publication_date", DateTime.Now))
End With

' Insert Record
dbConnection.Open
Try
dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try

Can someone tell me what is wrong?

Thanks,
Miguel

Nov 19 '05 #1
3 1558
I think it's the - in the column names...try wrapping them in []

INSERT INTO t_news ([title_pt-PT],
[title_en-GB], [text_pt-PT], [text_en-GB], publication_date) VALUES
(@title_pt-PT, @title_en-GB, @text_pt-PT, @text_en-GB,
@publication_date)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
Hello,

I need to add a new record to an ACCESS database.

I get the error: Syntax error in INSERT INTO statement.

I have no idea what am I doing wrong. This is my code:

' Set Connection
Dim connectionString As String = AppSettings("connectionString")
Dim dbConnection As IDbConnection = New OleDbConnection(connectionString)

' Set Query
Dim queryString As String = "INSERT INTO t_news (title_pt-PT,
title_en-GB, text_pt-PT, text_en-GB, publication_date) VALUES
(@title_pt-PT, @title_en-GB, @text_pt-PT, @text_en-GB, @publication_date)"

Dim dbCommand As IDbCommand = New OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

' Add Parameters
With dbCommand.Parameters
.Add(New OleDbParameter("@title_pt-PT", "sample"))
.Add(New OleDbParameter("@title_en-GB", "sample"))
.Add(New OleDbParameter("@text_pt-PT", "sample"))
.Add(New OleDbParameter("@text_en-GB", "sample"))
.Add(New OleDbParameter("@publication_date", DateTime.Now))
End With

' Insert Record
dbConnection.Open
Try
dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try

Can someone tell me what is wrong?

Thanks,
Miguel

Nov 19 '05 #2
Hello,

I had that before but I took it. In fact I found where the problem is
but I am not able to solve it.

I am getting a "Data type mismatch in criteria expression" with the
publication_date field.

In my Access database I have this field as "Date/Time".
I don't know what is going wrong here.

Do you know?

Thanks,
Miguel

"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:karl REMOVE @ REMOVE openmymind REMOVEMETOO .
ANDME net:
I think it's the - in the column names...try wrapping them in []

INSERT INTO t_news ([title_pt-PT],
[title_en-GB], [text_pt-PT], [text_en-GB], publication_date) VALUES
(@title_pt-PT, @title_en-GB, @text_pt-PT, @text_en-GB,
@publication_date)

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"Shapper" <mdmoura*NOSPAM*@gmail.*DELETE2SEND*com> wrote in message
news:ed**************@TK2MSFTNGP09.phx.gbl...
Hello,

I need to add a new record to an ACCESS database.

I get the error: Syntax error in INSERT INTO statement.

I have no idea what am I doing wrong. This is my code:

' Set Connection
Dim connectionString As String = AppSettings("connectionString")
Dim dbConnection As IDbConnection = New OleDbConnection(connectionString)

' Set Query
Dim queryString As String = "INSERT INTO t_news (title_pt-PT,
title_en-GB, text_pt-PT, text_en-GB, publication_date) VALUES
(@title_pt-PT, @title_en-GB, @text_pt-PT, @text_en-GB, @publication_date)"

Dim dbCommand As IDbCommand = New OleDbCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

' Add Parameters
With dbCommand.Parameters
.Add(New OleDbParameter("@title_pt-PT", "sample"))
.Add(New OleDbParameter("@title_en-GB", "sample"))
.Add(New OleDbParameter("@text_pt-PT", "sample"))
.Add(New OleDbParameter("@text_en-GB", "sample"))
.Add(New OleDbParameter("@publication_date", DateTime.Now))
End With

' Insert Record
dbConnection.Open
Try
dbCommand.ExecuteNonQuery
Finally
dbConnection.Close
End Try

Can someone tell me what is wrong?

Thanks,
Miguel


Nov 19 '05 #3
Specify datatype of last parameter

dbCommand.Parameters.Add("@publication_d*ate", OleDbType.DBDate).Value
= "yyyymmdd";

Here in add method first arg is parameter name
second is type of field
Refer msdn for add method of parameter collection of command.

bhawin13

Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: newbie_mw | last post by:
Hi, I need urgent help with a novice problem. I would appreciate any advice, suggestions... Thanks a lot in advance! Here it is: I created a sign-up sheet (reg.html) where people fill in their...
16
by: Philip Boonzaaier | last post by:
I want to be able to generate SQL statements that will go through a list of data, effectively row by row, enquire on the database if this exists in the selected table- If it exists, then the colums...
3
by: Nicolae Fieraru | last post by:
Hi All, I have a problem and I can't figure out how to solve it. My database has three tables: tblCustomers, with CustomerId and CustomerName tblProducts, with ProductId and ProductCode...
3
by: celineusa | last post by:
Hello! Here is part of my database: tblStudents: StudentID tblMajorsAndStudents: StudentID, MajorID tblMajors: MajorID tblMajorsAndClasses: MajorID, ClassID, QuarterTaken tblClasses:...
5
by: Brad Baker | last post by:
I'm trying to write a simple asp.net page which updates some data in a SQL database. At the top of the page I have the following code: <%@ Page Language="C#" Debug="true" %> <%@ import...
4
by: Mark Olbert | last post by:
I am struggling with trying to retrieve the value of an autoincrement identity field after a DetailsView Insert operation. The DetailsView is bound to an SqlDataSource control. So far as I can...
1
by: arial | last post by:
I have two problem. 1) My insert statement here is not working. It is not inserting value into the database. I am not getting any error message but I can not figured out why it is not...
5
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration:...
4
by: =?Utf-8?B?RXJpYyBGYWxza2Vu?= | last post by:
We’re storing our main entity in an insert only table which stores the history of past revisions, but we’re facing problems with storing this history as LINQ will only update the entity, and...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.