A
Arpan
A MS-Access database table has 4 columns named Col1, Col2, Col3 & Col4.
The datatype of Col1 is Number & the datatype of Col2, Col3 & Col4 are
Text.
In my ASP application, the column name as well as the record in a SQL
query gets generated dynamically, something like this:
<%
Dim strColumn, strRecord
strColumn=Request.QueryString("col")
strRecord=Request.QueryString("rec")
Dim strSQL
strSQL="SELECT * FROM MyTable WHERE " & strColumn & "='" & strRecord &
"'"
..............
..............
%>
Note that both the column name as well as the record are getting
generated dynamically.
Now if the value of strColumn is either Col2, Col3 or Col4, then
everything's fine but if the value of strColumn is Col1, then the
single quotes in the SQL query results in a datatype mismatch error
since strRecord gets enclosed within single quotes. For e.g. with
strColumn=Col1, assume that the value of strRecord is 10. Then the SQL
query becomes
SELECT * FROM MyTable WHERE Col1='10'
Now since the datatype of Col1 is Number, the above SQL query generates
the datatype mismatch error since 10 is enclosed within single quotes!
Any workaround to overcome this?
Thanks,
Arpan
The datatype of Col1 is Number & the datatype of Col2, Col3 & Col4 are
Text.
In my ASP application, the column name as well as the record in a SQL
query gets generated dynamically, something like this:
<%
Dim strColumn, strRecord
strColumn=Request.QueryString("col")
strRecord=Request.QueryString("rec")
Dim strSQL
strSQL="SELECT * FROM MyTable WHERE " & strColumn & "='" & strRecord &
"'"
..............
..............
%>
Note that both the column name as well as the record are getting
generated dynamically.
Now if the value of strColumn is either Col2, Col3 or Col4, then
everything's fine but if the value of strColumn is Col1, then the
single quotes in the SQL query results in a datatype mismatch error
since strRecord gets enclosed within single quotes. For e.g. with
strColumn=Col1, assume that the value of strRecord is 10. Then the SQL
query becomes
SELECT * FROM MyTable WHERE Col1='10'
Now since the datatype of Col1 is Number, the above SQL query generates
the datatype mismatch error since 10 is enclosed within single quotes!
Any workaround to overcome this?
Thanks,
Arpan