OleDbException: Data type mismatch in criteria expression.

B

Bobby Edward

Using Access db with VS2008 (ASP.NET/VB.NET)....

On the INSERT command I get this error: System.Data.OleDb.OleDbException:
Data type mismatch in criteria expression.

I haven't found a solution yet in my research. Any idea what I might be
missing?

**************
Datasource setup as follows:
<asp:AccessDataSource ID="AccessDataSource1"
runat="server"
DataFile="~/BeachFuneral.mdb"
InsertCommand="INSERT INTO [ObitComments]
([ObitId], [CommentBy], [CommentEmail], [CommentRelation],
[CommentApproved], [CommentDateTime], [ObitComment]) VALUES (?, ?, ?, ?, ?,
?, ?)" >
<InsertParameters>
<asp:parameter Name="ObitId" />
<asp:parameter Name="CommentBy" />
<asp:parameter Name="CommentEmail" />
<asp:parameter Name="CommentRelation" />
<asp:parameter Name="CommentApproved" />
<asp:parameter Name="CommentDateTime" />
<asp:parameter Name="ObitComment" />
</InsertParameters>
</asp:AccessDataSource>

**************
Code to insert as follows:
With Me.AccessDataSource1
.InsertParameters("ObitId").DefaultValue =
Request.QueryString("Id")
.InsertParameters("CommentBy").DefaultValue =
Me.txtFullName.Text
.InsertParameters("CommentEmail").DefaultValue =
Me.txtEmail.Text
.InsertParameters("CommentRelation").DefaultValue =
Me.txtRelationship.Text
.InsertParameters("CommentApproved").DefaultValue = True
.InsertParameters("CommentDateTime").DefaultValue = Now.ToString
.InsertParameters("ObitComment").DefaultValue =
Me.txtComment.Text
End With
Try
Me.AccessDataSource1.Insert()
Catch ex As Exception
Response.Write(ex.ToString)
Exit Sub
Finally
' if ok then move on...
Response.Redirect("Obit.aspx?Id=" & Request.QueryString("Id"))
End Try
 
K

Kevin Spencer

You have not identified what data types your database is using, either in
this message, or in your code. However, you are attemtping to insert all
string values (text data type), with the exception of one field
(CommentApproved) which you are inserting a boolean value into. So, unless
all of the fields in the table are text except for that one, you would
certainly get that exception.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top