Last active
August 29, 2015 13:55
VB 2010 Insert InTo Values with Apostrophe from Variables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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