Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Getting ASP.NET Error Message
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Getting ASP.NET Error Message

 Post Reply Post Reply Page  12>
Author
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post Topic: Getting ASP.NET Error Message
    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 & "'"

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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


Back to Top
Diep-Vriezer View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 August 2003
Location: Netherlands
Status: Offline
Points: 831
Post Options Post Options   Thanks (0) Thanks(0)   Quote Diep-Vriezer Quote  Post ReplyReply Direct Link To This Post Posted: 25 September 2004 at 5:39am
The non braking spaces are also not required right? (&nbsp;)
Gone..
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 25 September 2004 at 5:42am
Right. Looks like WWF mucked it up for some reason
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post 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.

Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 25 September 2004 at 12:46pm
Make sure that strProdID is an integer as you have declared it as a string.
Back to Top
Misty View Drop Down
Senior Member
Senior Member
Avatar

Joined: 06 February 2002
Location: United States
Status: Offline
Points: 711
Post Options Post Options   Thanks (0) Thanks(0)   Quote Misty Quote  Post ReplyReply Direct Link To This Post 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.  
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
 Post Reply Post Reply Page  12>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.