I have this code to update my SQL database from data in a text box in VB. I need to use the options if the text contains the tic character, or quote "etc. etc. Here is what I have:
dbConn = New SqlConnection("server=.\SQLEXPRESS;Integrated Security=SSPI; database=FATP") dbConn.Open() MyCommand = New SqlCommand("UPDATE SeansMessage SET Message = '" & TicBoxText.Text & _ "'WHERE Number = 1", dbConn) MyDataReader = MyCommand.ExecuteReader() MyDataReader.Close() dbConn.Close()
And this is my lame attempt to set a parameter from what I saw on the Internet that I do not understand very well.
dbConn = New SqlConnection("server=.\SQLEXPRESS;Integrated Security=SSPI; database=FATP") dbConn.Open() MyCommand = New SqlCommand("UPDATE SeansMessage SET Message = @'" & TicBoxText.Text & _ "'WHERE Number = 1", dbConn) MyDataReader = MyCommand.ExecuteReader() MyDataReader.Close() dbConn.Close()
How do you do this? The reason, if there is a mark in the text box, when I run the code, it crashes.
source share