gpt4 book ai didi

c# - 字符串或二进制数据将被截断 - 添加新行( Entity Framework )

转载 作者:行者123 更新时间:2023-11-30 19:25:23 25 4
gpt4 key购买 nike

当我尝试添加新行时出现此错误。

HexStringToByteArray("0x546F206A65737420707573747920706C696B0D0A");

String or binary data would be truncated.\r\nThe statement has been terminated.

attachement.ATF_ID = 244512;
attachement.ATF_WFDID = 160489;
attachement.ATF_ATTID = 244512;
attachement.ATF_Name = "teska14.txt";
attachement.ATF_FileType = ".txt";
attachement.ATF_Value = HexStringToByteArray("0x546F206A65737420707573747920706C696B0D0A");
attachement.ATF_FileIsOcr = 0;
attachement.ATF_CreatedBy = "test";
attachement.ATF_UpdatedBy = "test";
attachement.ATF_OrginalValueHash = HexStringToByteArray("0x4C35C01D7E10FB7F7440D39932265E7C7F09A4D17FEFB55AE9E1DDAC97AD373E");
attachement.ATF_OrginalName = "test.txt";
attachement.ATF_Version = -1;
context2.WFAttachmentFiles.AddObject(attachement);
//context.AddToWFAttachmentFiles(attachement);
//context.WFAttachmentFiles.AddObject(attachement);
context2.SaveChanges();

HEC代码:

public static byte[] HexStringToByteArray(string hexString)
{
if (string.IsNullOrWhiteSpace(hexString))
throw new ArgumentNullException("hexString");

if (hexString.Length % 2 != 0)
throw new Exception("Invalid hex string");

var bytes = new byte[hexString.Length / 2];
for (int i = 2; i < bytes.Length; i++)
{
bytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
}
return bytes;
}

最佳答案

通常当您看到该错误消息时:

String or binary data would be truncated. The statement has been terminated.

这意味着其中一个数据库列不够大,无法容纳您要保存的数据。

在您的情况下,检查数据库中 ATF_OrginalValueHashATF_Value 列的大小,并可能增加它们

关于c# - 字符串或二进制数据将被截断 - 添加新行( Entity Framework ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28965462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com