Groups | Blog | Home
all groups > asp.net > june 2005 >

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


Shapper
6/30/2005 12:00:00 AM
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>
[quoted text, click to view]
Karl Seguin
6/30/2005 6:03:50 PM
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!)


[quoted text, click to view]

Shapper
6/30/2005 9:42:18 PM
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
bhawin13 NO[at]SPAM indiatimes.com
6/30/2005 9:52:20 PM
Specify datatype of last parameter

dbCommand.Parameters.Add("@publication_d=ADate", OleDbType.DBDate).Value
=3D "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
AddThis Social Bookmark Button