Data Type Mismatch in criteria Expression, Help~

Error in Explorer: 

Data type mismatch in criteria expression.
Following codings:
Dim lowestPrice As Double
Dim highestPrice As Double
lowestPrice = FormatCurrency(txtLow.Text, 2)
highestPrice = FormatCurrency(txtHigh.Text, 2)
lblLabel.Text = lowestPrice
..
..
"UNION " & _
"SELECT p.ProductID, p.ProductTitle FROM Product p " & _
"WHERE (p.Price > '" & FormatCurrency(lowestPrice, 2) & "' AND p.Price < '" & FormatCurrency(highestPrice, 2) & "') " & _
"ORDER BY p.ProductTitle"
I don't know where the error goes wrong in here.. previously because of the union missing one spacing that resulted in syntax error, after i inserted a space to it.. it shows me Data type mismatch the criteria expression. Is it because in my sql coding i cant use FormatCurrency for ASP.net? please give me a hand.. thank you
Contact me at: ryuichi_ogata86@hotmail.com
ICQ me at: 18750757
0
NorikoSakai
2/20/2005 7:06:28 AM
asp.net.sql-datasource 29906 articles. 0 followers. Follow

1 Replies
635 Views

Similar Articles

[PageSpeed] 25

Please abandon this approach and use parameters instead.  Use something like this:


Dim mySQL as string = "SELECT...." &_
"UNION " & _
"SELECT p.ProductID, p.ProductTitle FROM Product p " & _
"WHERE (p.Price > @lowestPrice AND p.Price < @highestPrice) " & _
"ORDER BY p.ProductTitle"
Dim myConnection as New SQLConnection(strConn)
Dim myCommand as New SQLCommand(mySQL, myConnection)
myCommand.CommandType = CommandType.Text
Dim myParameter1 As SqlParameter = New SqlParameter("@lowestPrice", SqlDbType.Money)
myParameter1.Value = lowestPrice
myCommand.Parameters.Add(myParameter1)
Dim myParameter2 As SqlParameter = New SqlParameter("@highestPrice", SqlDbType.Money)
myParameter2.Value = highestPrice
myCommand.Parameters.Add(myParameter2)

myConnection.Open()

This may not take care of your problem but will make your code more secure and should bring it closer.
Terri
Terri Morton
Engagement Manager, Neudesic

How to ask a question

0
tmorton
2/20/2005 4:13:31 PM
Reply:

Similar Artilces:

System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. HELP ME :)
Hellothis is my select code1 Dim ConnString1 As String = "Provider=Microsoft.Jet.OleDb.4.0;Data Source=|DataDirectory|Nwind2003(Good).mdb" 2 Dim sqlstring3 As String = "SELECT * FROM customers WHERE CustomerID= '" & CustomerID & "'" 3 Dim conn2 As New OleDbConnection(ConnString1)4 Dim cmd2 As New OleDbCommand(sqlstring3, conn2)5 cmd2.CommandType = CommandType.Text6 Response.Write(sqlstring3)7 8 conn2.Open()9 Dim reader As OleDbDataReader = cmd2.ExecuteRe...

Data type mismatch in criteria expression HELP!!!
Hi, Ive got the following problem, i keep on getting the following error Data type mismatch in criteria expression But when i change the value in the database table to Number and the value of strID to Int it works fine, but when i change the database table to text, and declare strID as a string it gives the message when i click on edit, i dont understand why as if it works for int is should work as string. any help would be greatly appreciated.. the error gives the following line as being responsible for the error Line 43: objDR=Cmd.ExecuteReader(system.data.Command...

Help with error: Data type mismatch in criteria expression
I have the following as part of a class I created to write and read to various .mdbs used at the school where I work:<code>    Function WriteDiscipline(ByVal FacID As String, ByVal HeadID As Long, _                ByVal StuID As String, ByVal DCode As String, _                ByVal InfracDate As Date) As Integer        Dim cmdSQL As New OleDbCommand       ...

Help needed / Data type mismatch in criteria expression.
Hi folks, I'm writing a .NET page using VB, attached to an Access database. I've run into the dreaded "Data type mismatch in criteria expression." error. I've reviewed what seems like hundreds of post on the same topic here, and as much as it galls me, I can't seem to figure out where the problem lies. I'm calling a parameterized query when a user selects a value from a listbox. As soon as this happens, I get two data type mismatch errors. 1        Sub lstCategories_SelectedIndexChanged(ByVal s As Object, ByVal e As EventArgs) Ha...

Data type mismatch in criteria expression HELP PLEASE
Hi im having a small problem, The problem is when i have my database table feild changed to a string and i declare strID as a string it gives the following error Data type mismatch in criteria expression but when the database table feild is changed to number and strID is declared as integer is works fine, no problems, i cant understand why it wont work when its changed to string, i would leave it as an integer but the rest of the system needs the database table feild to be a string Any help at all as to why it causing this prob...

Help im geting error Data type mismatch in criteria expression.
   Help im geting error Data type mismatch in criteria expression. How ca i get this to work ==========================================================================Protected Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click AccessDataSource1.UpdateCommand = "UPDATE `myguestbook` SET `author` = ?, `subject` = ?, `comments` = ? WHERE `PrimaryKey` = ?"Dim author As New ControlParameter("author", "TextBox1", "Text") AccessDataSource1.UpdateParameters.Add(author)Dim subject As New ControlParamet...

System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.
Hi Forum, I have a login script working using text as password, i want to change this to a number, format (000) 000-000, when i submit 025987654 which is formated (025) 987-654 in a field im receiving; Data type mismatch in criteria expression. Any help out there!!! Thanks Paul if the password is truly a number, then you need to drop the quotes from around it when you build the sql statement i.e. select * from tblUser WHERE Password=025987654 and NOT select * from tblUser WHERE Password='025987654' Mike Banavige~~~~~~~~~~~~Need a site code sample in a different language? T...

System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. #2
I am having trouble using OleDb within an ASP.NET application (C#) to write to a Yes/No data field in Access. I have a checkbox on my ASP.NET page and want this to save to a Yes/No field in an Access database. No matter what I try I get a "data type mismatch" message. I've tried the following variations to no avail:1.cmd.Parameters.Add("@SubsidyDoc", this.cbLeaseSubsidy.Checked);2.if (this.cbLeaseSubsidy.Checked == true)      cmd.Parameters.Add("@SubsidyDoc","-1"); else     cmd.Parameters.Add("@SubsidyDo...

Data type mismatch in criteria expression.
       Server Error in '/' Application. Data type mismatch in criteria expression. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.Data.OleDb.OleDbException: Data type mismatch in criteria expression.Source Error: Line 21: {Line 22: Line 23: this.SqlDataSource1.Insert();Line 24: Line 25: Source File: E:\OrderWebApp\OrderWebApp...

Data type mismatch in criteria expression.
Get this error when tring to run th efollowing code. Function close(ByVal status As String, ByVal dtnow As DateTime) As Integer Dim connectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Ole DB Services=-4; Data Source=D:\Documents an"& _ "d Settings\Mathew\My Documents\Auction.mdb" Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConnection(connectionString) Dim queryString As String = "UPDATE [Auction] SET [Status]=@Status WHERE ([Auction].[End_Date] <= @dtnow)" ...

Data Type Mismatch in Criteria Expression
hi guys,  I getting this error. Here is my SQL statement, Thinks this may be why im gettin the error. OleDbCommand myCommand = new OleDbCommand("UPDATE patient SET title = '" + title + "', fName = '" + fName + "', sName = '" + sName + "', address1 = '" + address1 + "', address2 = '" + address2 + "', address3 = '" + address3 + "', postcode = '" + postcode + "', contactNumber = '" + contactNumber + "', DOB = '" + DOB + "'...

Data type mismatch in criteria expression.
System.Data.OleDb.OleDbException: Data type mismatch in criteria expression. i'm getting this error while executing my onsert query. I verified all of the types of the values I'm entering and i'm not getting any positive results. Can someone help me out here? the error is generated at the "executenonquery" line Dim connectionString As String = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("..\data\Original_MLBDlicensing.mdb") Dim dbConnection As System.Data.IDbConnection = New System.Data.OleDb.OleDbConn...

Data type mismatch in criteria expression
Hi, I'm getting this error "System.Data.OleDb.OleDbException: Data type mismatch in criteria expression" and I don't know how to fix it.  I try it many differently ways and none of them work. I have a formview with insert template.  I'm using Access database.  The table has three column - id, title, users.  The datatype is "text" for both fields.  The problem is the users field.  I want to grab the value form checkboxlist and insert into database but getting the error.  <asp:FormView ID="FormView1" runat="...

Data type mismatch in criteria expression
Hiya. I'm using Access2000 and DBI::ODBC. I'm trying to insert into a table called Volunteers, and I continually get this error: -------------- Died while executing:<br>[Microsoft][ODBC Microsoft Access Driver] Data type mismatch in criteria expression. (SQL-22005)(DBD: st_execute/SQLExecute err=-1)<hr> at c:\inetpub\wwwroot\EBA\cgi-bin\edit_volunteers.pl line 472. -------------- I don't understand what data type is incorrect though. There are only 2 fields which have a specific criteria: 1) Confirmed: "Yes" or "No 2) Position: maaaany d...