[英]How to fix “String or binary data would be truncated” when convert .docx file to binary and insert into varbinary(Max)?
我使用FileStream使用Varbinaray(Max)將文件插入到列中。 這是我的示例代碼:
byte[] dataBytes = File.ReadAllBytes(fileNameAndPath);
string insertCommand = string.Format(@" INSERT INTO [dbo].[ts000Attachments] ([Data]) values (@Data)");
command.Parameters.Add("@Data",SqlDbType.VarBinary,-1).Value = dataBytes;
command.ExecuteNonQuery();
上面的代碼使用.doc文件。 如何解決此問題。
根據以下鏈接,此問題全部與sql中的列大小有關:
堆棧溢出:
微軟:
代碼項目:
還要確保在表上激活了FileStream功能。 對我來說,我不知道為什么我的表沒有使用FileStream功能創建。 因此,我放下了表並重新創建了它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.