PackerFanatic
10-24-2005, 11:25 AM
But this question is bugging me and I can't figure it out.
I have this SQL statement I wrote for work and it seems to have an error when one certain thing is entered. Here is the statement:
"SELECT TRTEXT_ID, TRTEXT_TEXT_NUM, TRTEXT_PUBLISHER_TXT, TRTEXT_AUTHOR_TXT, TRTEXT_TITLE_TXT, TRTEXT_EDITION_NUM, TRTEXT_ISBN_TXT, TRTEXT_LISTPRICE_AMT, TRTEXT_ADOPTION_TRM, TRTEXT_DELETION_TRM, TRTEXT_STATUS_CD, TRTEXT_SHELFLOC_TXT, TRTEXT_SYSDATE_TMS, TRTEXT_USER_NM, TRTEXT_COMMENTS_TXT
FROM TRTEXT
WHERE (TRTEXT_STATUS_CD = 'ACTIVE') AND (TRTEXT_"+searchOption+"_TXT LIKE '"+tbSearch.Text.ToUpper()+"%')ORDER BY TRTEXT_"+searchOption+"_TXT"
The bolded area is the place where we are having an issue. As you can see, there are single quotes around the search text and % (which is needed for the like statement) The problem is when the user enters a single quote in that text field (like they are searching for O'Rourke for instance, or something to that effect) It bombs the statement, since there is then a quote not ended. I have tried using parameters but I am not sure how to do it in the middle of a statement like that while still keeping the single quotes and all that. This is an Oracle statement (as opposed to an OleDB one), not sure if that makes a difference. Thanks in advance guys.
I have this SQL statement I wrote for work and it seems to have an error when one certain thing is entered. Here is the statement:
"SELECT TRTEXT_ID, TRTEXT_TEXT_NUM, TRTEXT_PUBLISHER_TXT, TRTEXT_AUTHOR_TXT, TRTEXT_TITLE_TXT, TRTEXT_EDITION_NUM, TRTEXT_ISBN_TXT, TRTEXT_LISTPRICE_AMT, TRTEXT_ADOPTION_TRM, TRTEXT_DELETION_TRM, TRTEXT_STATUS_CD, TRTEXT_SHELFLOC_TXT, TRTEXT_SYSDATE_TMS, TRTEXT_USER_NM, TRTEXT_COMMENTS_TXT
FROM TRTEXT
WHERE (TRTEXT_STATUS_CD = 'ACTIVE') AND (TRTEXT_"+searchOption+"_TXT LIKE '"+tbSearch.Text.ToUpper()+"%')ORDER BY TRTEXT_"+searchOption+"_TXT"
The bolded area is the place where we are having an issue. As you can see, there are single quotes around the search text and % (which is needed for the like statement) The problem is when the user enters a single quote in that text field (like they are searching for O'Rourke for instance, or something to that effect) It bombs the statement, since there is then a quote not ended. I have tried using parameters but I am not sure how to do it in the middle of a statement like that while still keeping the single quotes and all that. This is an Oracle statement (as opposed to an OleDB one), not sure if that makes a difference. Thanks in advance guys.