Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
If you try to insert a string into SQL that has a ...
Author:
Kevin Henderson
E-mail:
Click to e-mail author
Submitted:
4/11/2000
Version:
VB4
Compatibility:
VB4, VB5, VB6
Category:
Databases
Views:
10380
If you try to insert a string into SQL that has a single quote in it, it will delimit the string and cause an error. This sub will correct it. Code for checking if there is a Quote in the string. SQL will delimit a string when inserting, cause an error, so we have to work around it. By placing two single quotes together, SQL will place a single one in it's place when the record is inserted. This Sub should be used for straight SQL Insert or select statments "Insert Into Mytable (field1,Field2) Values ('" & CheckForQuote text1.text & "','" & CheckForQuote text2.text & "') Or you can use it in the Let statement of a property in a custom Class.
Declarations:
none
Code:
Public Sub CheckForQuote(ByRef sStringToCheck As String) Dim intRetVal As Integer intRetVal = 0 intRetVal = InStr(1, sStringToCheck, "'", vbBinaryCompare) If Not intRetVal = 0 Then ' quotation mark found sStringToCheck = Left(sStringToCheck, intRetVal - 1) & "''" & Right(sStringToCheck, Len(sStringToCheck) - intRetVal) End If Do While intRetVal <> 0 intRetVal = InStr(intRetVal + 2, sStringToCheck, "'", vbBinaryCompare) If Not intRetVal = 0 Then ' quotation mark found sStringToCheck = Left(sStringToCheck, intRetVal - 1) & "''" & Right(sStringToCheck, Len(sStringToCheck) - intRetVal) End If Loop End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement