如何解决字符串或二进制数据将被截断错误消息
当您尝试插入一些对于字段而言太大的数据时,将显示此消息。
这里的主要候选者是Email
-您只需将其设置为15
字符,而大多数电子邮件地址将会更大!将其增加到,255
然后重试。
还要检查所有其他项,尤其是像这样的小项Mobile
。
解决方法
我收到以下错误消息:
字符串或二进制数据将被截断
我试图增加列的大小,但是没有运气,我已经对代码进行了两次检查,但似乎找不到任何问题。其在插入过程中:
SqlCommand insert = new SqlCommand(@"INSERT
into orderDetails
(orderID,Name,Phone,Mobile,Email,DelName,DelRoad,DelTown,DelCity,DelCounty,DelPostCode,BilName,BilRoad,BilTown,BilCity,BilCounty,BilPostCode)
values
(@orderID,@Name,@Phone,@Mobile,@Email,@DelName,@DelRoad,@DelTown,@DelCity,@DelCounty,@DelPostCode,@BilName,@BilRoad,@BilTown,@BilCity,@BilCounty,@BilPostCode)",connection);
insert.Parameters.AddWithValue("@orderID",ID);
insert.Parameters.AddWithValue("@Name",name);
insert.Parameters.AddWithValue("@Phone",customer.Phone);
insert.Parameters.AddWithValue("@Mobile",customer.Mobile);
insert.Parameters.AddWithValue("@Email",customer.Email);
insert.Parameters.AddWithValue("@DelName",customer.DelName);
insert.Parameters.AddWithValue("@DelRoad",customer.DelRoad);
insert.Parameters.AddWithValue("@DelTown",customer.DelTown);
insert.Parameters.AddWithValue("@DelCity",customer.DelCity);
insert.Parameters.AddWithValue("@DelCounty",customer.DelCounty);
insert.Parameters.AddWithValue("@DelPostCode",customer.DelPostCode);
insert.Parameters.AddWithValue("@BilName",customer.BilName);
insert.Parameters.AddWithValue("@BilRoad",customer.BilRoad);
insert.Parameters.AddWithValue("@BilTown",customer.BilTown);
insert.Parameters.AddWithValue("@BilCity",customer.BilCity);
insert.Parameters.AddWithValue("@BilCounty",customer.BilCounty);
insert.Parameters.AddWithValue("@BilPostCode",customer.BilPostCode);
insert.ExecuteNonQuery();
这是我的表定义代码:
CREATE TABLE [dbo].[orderDetails] (
[orderID] INT NOT NULL,[Name] NCHAR (100) NULL,[Phone] NCHAR (100) NULL,[Mobile] NCHAR (15) NULL,[Email] NCHAR (15) NULL,[DelName] NCHAR (100) NULL,[DelRoad] NCHAR (100) NULL,[DelTown] NCHAR (100) NULL,[DelCity] NCHAR (100) NULL,[DelCounty] NCHAR (100) NULL,[DelPostCode] NCHAR (100) NULL,[BilName] NCHAR (100) NULL,[BilRoad] NCHAR (100) NULL,[BilTown] NCHAR (100) NULL,[BilCity] NCHAR (100) NULL,[BilCounty] NCHAR (100) NULL,[BilPostCode] NCHAR (100) NULL,PRIMARY KEY CLUSTERED ([orderID] ASC)
);
客户类别
public class Customer
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Phone { get; set; }
public string Mobile { get; set; }
public string Email { get; set; }
public string DelName { get; set; }
public string DelRoad { get; set; }
public string DelTown { get; set; }
public string DelCity { get; set; }
public string DelCounty { get; set; }
public string DelPostCode { get; set; }
public string BilName { get; set; }
public string BilRoad { get; set; }
public string BilTown { get; set; }
public string BilCity { get; set; }
public string BilCounty { get; set; }
public string BilPostCode { get; set; }
public bool sameasDel { get; set; }
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。