| | |
problem with quotes in SQL statement
Please support our Visual Basic 4 / 5 / 6 advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Dec 2007
Posts: 7
Reputation:
Solved Threads: 0
Hi
I need to insert a string in a database but the string might or might not contain a quotes('). There is no problem if there is no quotes. But in case of quotes it throws a syntax error in insert statement and that obvious also. What i am thinking is to do some formatting all the time for all the strings before inserting do the insertion. Is there anyother to achieve this.. Thanks for the suggestions.
Ashish
I need to insert a string in a database but the string might or might not contain a quotes('). There is no problem if there is no quotes. But in case of quotes it throws a syntax error in insert statement and that obvious also. What i am thinking is to do some formatting all the time for all the strings before inserting do the insertion. Is there anyother to achieve this.. Thanks for the suggestions.
Ashish
•
•
•
•
Is there anyother to achieve this
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
Dim strInsert as String Dim intLength as integer if Mid(strInsert, 1,1) = "'" then strInsert = right(strInsert, len(strInsert) -1) end if intLength = len(strInsert) if Mid(strInsert, intLength, 1) = "'" then strInsert = Left(strInsert, intLength -1) Endif
Hank
•
•
Join Date: Apr 2007
Posts: 106
Reputation:
Solved Threads: 16
See if this helps: http://support.microsoft.com/default.aspx/kb/178070
•
•
Join Date: Sep 2007
Posts: 1
Reputation:
Solved Threads: 0
I had a similar problem...I wanted to leave any single quotes or double quotes as they were when read in from my datasource but when trying to do this it caused problems with my SQL string in my VB code.
This is how I solved it: If my datasource involved quotes I used the string function Replace to make them two single quotes in my SQL statement ie:
This is how I solved it: If my datasource involved quotes I used the string function Replace to make them two single quotes in my SQL statement ie:
Visual Basic 4 / 5 / 6 Syntax (Toggle Plain Text)
strQuery = "update files set files." & sField & " = '" & Replace(strOut, "'", "''") & "' where whatever=" & adoRS("whatever")
I agree with you duncanj that problem is very common when it comes to queries, most programmer used that function (Replace())
A conclusion is the place where you got tired of thinking. http://www.martin2k.co.uk/forums/index.php?showforum=4
http://www.a1vbcode.com/a1vbcode/vbforums/Forum3-1.aspx
http://www.developerfusion.co.uk/for...orum&ForumID=4
![]() |
Similar Threads
- mysql_fetch_array(): supplied argument is not a valid MySQL (PHP)
- Warning: mysql_num_rows(): supplied argument is not a valid MySQL result (PHP)
- Qeury problem(plz help) (PHP)
- nested joins, from mdb. Possible? (Visual Basic 4 / 5 / 6)
- Problem with input (ASP)
Other Threads in the Visual Basic 4 / 5 / 6 Forum
- Previous Thread: Help needed please VB5
- Next Thread: Stop a keyboard key input
| Thread Tools | Search this Thread |
Tag cloud for Visual Basic 4 / 5 / 6
* 6 429 2007 access activex add age append application basic beginner birth bmp calculator cd cells.find click client code college column component connection connectionproblemusingvb6usingoledb copy creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit error excel excelmacro file filename form hardware header iamthwee image inboxinvb internetfiledownload keypress label listbox listview liveperson login looping machine microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading record refresh remotesqlserverdatabase report retrieve save search sendbyte sites sort sql sql2008 sqlserver subroutine table tags textbox time timer urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web window windows






