Print Page | Close Window

Getting ASP.NET Error Message

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=11938
Printed Date: 29 March 2026 at 3:12am
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Getting ASP.NET Error Message
Posted By: Misty
Subject: Getting ASP.NET Error Message
Date Posted: 24 September 2004 at 10:37pm

I am getting an ASP.Net error. I got the code from a college professor's example. I don't understand what's wrong. I have pasted some of my code below.

Here's the error message:

Exception Details: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.

Source Error:

Line 55:          
Line 56:         'Execute the SQL statement -- using the command object -- to populate the DataReader 
Line 57:         m_dtrMusic = objCommand.ExecuteReader() 
Line 58: 
Line 59:         'Read the record into the DataReader object 

Let me give you parts of the code for modify_record2.aspx that are significant to why I may be getting this error message:

   <%@ Page Language="VB" Debug="True" Trace="True" %>

<%@ import Namespace="System.Data" %>

<%@ import Namespace="System.Data.OleDb" %>

<script runat="server">

 

'Make this DataReader object module-leve in scope so that we

'can bind directly to its field values

dim m_dtrMusic As OleDbDataReader

'---------------------------------------------

' name: DisplayRecord(strProdID as String)

'---------------------------------------------

Sub DisplayRecord(strProdID as String)

 

 

        Dim strConnect As String

        Dim objConnect As New OleDbConnection()

        Dim strSQL as String

        Dim objCommand As New OleDbCommand()

        Dim path

        Dim databaseName

 

        databaseName = ""

 

        path = ""

       

        'Create Connection object

        strConnect    = "Provider=Microsoft.Jet.OLEDB.4.0;Data " _

                                                    & "Source=" & path & "\" & databaseName

        objConnect.ConnectionString = strConnect

        objConnect.Open()        

 

        

        'Build SQL string

        strSQL = "Select * From MusicInventory " & _

                                   " Where ID=" & "'" & strProdID & "'"




Replies:
Posted By: Mart
Date Posted: 25 September 2004 at 4:11am
The problem is with the SQL Query... Change

strSQL = "Select * From MusicInventory " & _

         &nbs p;          &n bsp;               " Where ID=" & "'" & strProdID & "'"



To this:


strSQL = "Select * From MusicInventory " & _

         &nbs p;          &n bsp;               " Where ID=" & strProdID



The problem was that you were surrounding the ID= with quotation marks, and you can't use them with those fields




Posted By: Diep-Vriezer
Date Posted: 25 September 2004 at 5:39am
The non braking spaces are also not required right? (&nbsp;)

-------------
Gone..


Posted By: Mart
Date Posted: 25 September 2004 at 5:42am
Right. Looks like WWF mucked it up for some reason


Posted By: Misty
Date Posted: 25 September 2004 at 12:28pm

Mart,

I changed the SQL Query, but I am still getting the same error message. I think that there's something wrong with m_dtrMusic = objCommand.ExecuteReader(), but I don't understand what's wrong. It says something about it being a data type mismatch.

Can anyone help me to figure out how to fix this problem with m_dtrMusic.



Posted By: Mart
Date Posted: 25 September 2004 at 12:46pm
Make sure that strProdID is an integer as you have declared it as a string.


Posted By: Misty
Date Posted: 25 September 2004 at 1:50pm
I found out that the strProdID is fine. In fact, it showed 9 which was correct for the certain querystring that it came from. It is obvious that there's something wrong with m_dtrMusic. Maybe there is something missing. Please look at all of the bolded text in my code.  


Posted By: Mart
Date Posted: 25 September 2004 at 2:22pm
Theres not neccessairly anything wrong with your reader, the exception is being thrown on the ExecuteReader line which would usually mean theres something wrong with your SQL Query. Can you post your modified one?


Posted By: Misty
Date Posted: 25 September 2004 at 4:22pm

Mart,

I have found out what's wrong. It's actually the SQL String. I thought I had made change to the SQL String when I FTPed it earlier. I guess I didn't save the changes. It is working now. Thank you for your help!




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net