![](/img/trans.png)
[英]Read UTF8(XML) Data from SQL Server 2005 the most efficient way
[英]Inserting UTF8 data into image field in sql server 2005 from c#
我有一個使用utf8編碼的xml標記組成的字符串。 當我將其插入sql server image filed時,它僅插入前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();
結果在類型為image的內容字段中: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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.