running32
asked on
Write to database when string contains a '
I am trying to wrtie the contents of text box to a database but I am getting and error when there is a ' in the text, example justine's
here is the the code I am using. strrelation2descp = " & txtsourcedes2.Text & ", I have tried single/double and just double quotes I still get the error. Thank you for your help
Dim cmd8 As New SqlClient.SqlCommand("UPDA TE tblHousehold set curchecking =CAST('" & txtchk.Text & "' as money),cursavings =CAST('" & txtsav.Text & "' as money),curcash =CAST('" & txtcash.Text & "' as money),curcds =CAST('" & txtcd.Text & "' as money) ,curproperty =CAST('" & txtprop.Text & "' as money),curassets =CAST('" & txtother.Text & "' as money),ysnfoodstamps = '" & ysnfs & "' ,strvehicle1 = '" & txtvech1.Text & "',strvehicle1model = '" & txtmod1.Text & "',strvehicle1year = '" & txtyear1.Text & "',curvehicle1owed = cast('" & txtamtowed1.Text & "'as money),strvehicle2 = '" & txtvech2.Text & "',strvehicle2model = '" & txtmod2.Text & "',strvehicle2year = '" & txtyear2.Text & "',strrelation1descp = " & txtsourcedes1.Text & ",strrelation2descp = " & txtsourcedes2.Text & ",strrelation3descp = " & txtsourcedes3.Text & ",strrelation4descp = " & txtsourcedes4.Text & ",strrelation5descp = " & txtsourcedes5.Text & ",curvehicle2owed = cast('" & txtamtowed2.Text & "'as money)where lngHouseid =" & SqlParametersDB.Name.lngho useid, Connection1)
Try
cmd8.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
here is the the code I am using. strrelation2descp = " & txtsourcedes2.Text & ", I have tried single/double and just double quotes I still get the error. Thank you for your help
Dim cmd8 As New SqlClient.SqlCommand("UPDA
Try
cmd8.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.Message)
End Try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Cursed refresh button....Jon Raymond beat me to it :)
ASKER
thank you