| | |
problem with quotes in SQL statement
![]() |
•
•
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: 102
Reputation:
Solved Threads: 14
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 |
* 6 2007 access activex add age basic beginner birth bmp calculator cd cells.find click client code college connection connectionproblemusingvb6usingoledb creat ctrl+f data database datareport date delete dissertations dissertationthesis dissertationtopic edit excel excelmacro file filename form header iamthwee image inboxinvb internetfiledownload listbox listview liveperson login looping microsoft movingranges number objectinsert open oracle password prime program prompt range-objects readfile reading remotesqlserverdatabase report save search sendbyte sites sql sql2008 sqlserver subroutine tags time urldownloadtofile vb vb6 vb6.0 vba visual visualbasic visualbasic6 web windows






