c# - Append values to a column value in database -
c# - Append values to a column value in database -
i want append big string values existing values of column value in db. column set nvarchar(max)
. when trying, first few parts of new string appending old value. others not appending. please suggest .
string initial_result ="xxxxxx";//reading values db column , assigning string string final_result="yyyyyyyyyy";//lengthier 1 sqlcommand cmd71 = new sqlcommand("update details set result='" + initial_result + "'+'"+finalresult+"' student_id ='11' ", con7); cmd71.executenonquery();
because using unnecessary single quotes when concatenate initial_result
, finalresult
values.
result='" + initial_result + "'+'"+finalresult+"' ^ ^
but more important, should utilize parameterized queries. kind of string concatenations open sql injection attacks.
also utilize using
statement dispose database connections , objects.
using (sqlconnection con7 = new sqlconnection(cs)) { using (sqlcommand cmd71 = con7.createcommand()) { cmd71.commandtext = "update details set result = @result student_id ='11'"; cmd71.parameters.add("@result", sqldbtype.nvarchar).value = initial_result + finalresult; cmd71.executenonquery(); } }
c# sql asp.net sql-server
Comments
Post a Comment