Inserting UTF8 data into image field in sql server 2005 from c# -


i have string made of of xml markup encoded using utf8. when insert sql server image filed inserts first 28 bytes or characters.

here code:

  utf8encoding utf8 = new utf8encoding();   byte[] encodedbytes = utf8.getbytes(file.value);   string update = string.format("update xdpath set content = '{0}' dpath = '{1}';", encodedbytes, file.key);   sqlcommand com = new sqlcommand(update, conn);   com.executenonquery();   

result in content field of type image : 0x53797374656d2e427974655b5d.

there content in file verbose. please help.

use sql parameters

sqlcommand imagecommand = new sqlcommand("", (sqlconnection)connection, (sqltransaction)transaction);  imagecommand.commandtext = string.format(@"update xdpath set content = @bytearray dpath = '{0}'",file.key);  imagecommand.parameters.add("@bytearray", sqldbtype.image).value = (object)encodedbytes ?? dbnull.value; 

Comments