Skip to content

Instantly share code, notes, and snippets.

@facebookegypt
Last active August 29, 2015 13:55
VB 2010 Insert InTo Values with Apostrophe from Variables
'Visual Basic Online Course
'VB 2010 Insert InTo Values with Apostrophe
Function SqlStrAps(ByVal ToStr As String) As String
SqlStrAps = "'" & Replace(ToStr, "'", "''") & "'"
End Function
'_OR, you can do this .
Dim SqlStr As String = _
"Insert Into Table_Name (Field1,Field2,Field3_With_Apostrophe)"
SqlStr = SqlStr + " Values ('" & TextBox1.Text & "', _
'" & TextBox2.Text & "', '" & TextBox3.Text.Replace("'", "''") & "')"
With CMD
.Connection = CN
.CommandType = CommandType.Text
.CommandText = SqlStr
End With
Dim SqlH As Integer
SqlH = CMD.ExecuteNonQuery
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment