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: 18750757Please 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.TextDim 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
No comments:
Post a Comment