C# 从c将UTF8数据插入SQLServer2005中的图像字段#

C# 从c将UTF8数据插入SQLServer2005中的图像字段#,c#,sql-server,utf-8,C#,Sql Server,Utf 8,我有一个由xml标记组成的字符串,我使用UTF8编码。当我将其插入sql server映像文件时,它只插入前28个字节或字符 这是我的密码: UTF8Encoding utf8 = new UTF8Encoding(); byte[] encodedBytes = utf8.GetBytes(file.Value); string update = String.Format("Update xdpath set content = '{0}' where dpath = '{1}'

我有一个由xml标记组成的字符串,我使用UTF8编码。当我将其插入sql server映像文件时,它只插入前28个字节或字符

这是我的密码:

  UTF8Encoding utf8 = new UTF8Encoding();
  byte[] encodedBytes = utf8.GetBytes(file.Value);
  string update = String.Format("Update xdpath set content = '{0}' where dpath = '{1}';", encodedBytes, file.Key);
  SqlCommand com = new SqlCommand(update, conn);
  com.ExecuteNonQuery();  
类型图像的内容字段中的结果:0x53797374656D2E427974655B5D

文件中有非常详细的内容。请帮忙

使用sql参数

SqlCommand ImageCommand = new SqlCommand("", (SqlConnection)connection, (SqlTransaction)Transaction);

ImageCommand.CommandText = string.Format(@"Update xdpath set content = @ByteArray where dpath = '{0}'",file.Key);

ImageCommand.Parameters.Add("@ByteArray", SqlDbType.Image).Value = (object)encodedBytes ?? DBNull.Value;