I Use FileStream to Insert file into column with Varbinaray(Max). This is my sample code :
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();
above code work with .doc file. How to fix this Problem.
According to below links, this issue is all about column size in sql:
StackOverflow:
SQL Server String or binary data would be truncated
SQL Server Error : String or binary data would be truncated
Microsoft:
String or binary data would be truncated" and field specifications
CodeProject:
String or binary data would be truncated. The statement has been terminated.
also make sure that FileStream feature is activated on your table. for me I don't know why my table did not create with FileStream Feature. so, I dropped the table and re-create it.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.