Monday, December 17, 2007

What will cause error Data-Type-Mismatch while using this SQL?

What will cause error Data-Type-Mismatch while using this SQL?


If the following SQL command is used in the ASP scripts:

strSQL= "SELECT * FROM Discuss WHERE ID='" & intID & "'"

We will get this error message:

Actually, this is a correct SQL. But why we still have this problem?

Let us see what is the difference in between the following SQL example:

SELECT * FROM Discuss WHERE ID='1'


And


SELECT * FROM Discuss WHERE ID=1


The first Command, the ID is a string; in the following command, the ID is an integer.

Now you know what is wrong in that example.

In the database, if the ID is integer:

We use this SQL to get the information


SELECT * FROM Discuss WHERE ID='1'


So the "type mismatch" error will come up.


No comments: