字符串或二进制数据将被截断的错误信息 [英] string or binary data would be truncated error message

查看:1286
本文介绍了字符串或二进制数据将被截断的错误信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到以下错误信息:




字符串或二进制数据将被截断。


< /块引用>

我试过增加柱的大小,但没有运气,我已经翻了一番通过代码检查,但不能似乎找到任何问题。它插入时:

 的SqlCommand插入=新的SqlCommand(@INSERT 
到ORDERDETAILS
(的orderID ,姓名,电话,手机,电子邮件,DelName,DelRoad,DelTown,DelCity,DelCounty,DelPostCode,BilName,BilRoad,BilTown,BilCity,BilCounty,BilPostCode)

(@orderID,@Name,@电话,@Mobile,@Email,@DelName,@DelRoad,@DelTown,@DelCity,@DelCounty,@DelPostCode,@BilName,@BilRoad,@BilTown,@BilCity,@BilCounty,@BilPostCode),连接);
insert.Parameters.AddWithValue(@单编号,身份证);
insert.Parameters.AddWithValue(@名,名);
insert.Parameters.AddWithValue(@电话,customer.Phone);
insert.Parameters.AddWithValue(@移动,customer.Mobile);
insert.Parameters.AddWithValue(@电子邮件,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]。[订单明细](
[单编号] INT NOT NULL,
[名] NCHAR(100)NULL,
[电话] NCHAR(100)NULL,
[移动] NCHAR(15)NULL,
[邮件] 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([单编号] ASC)
);



Customer类

 公共类客户
{
公共字符串名字{获得;组; }
公共字符串名字{获得;组; }
公共字符串电话{搞定;组; }
公共字符串移动{搞定;组; }
公共字符串电子邮件{获得;组; }
公共字符串DelName {搞定;组; }
公共字符串DelRoad {搞定;组; }
公共字符串DelTown {搞定;组; }
公共字符串DelCity {搞定;组; }
公共字符串DelCounty {搞定;组; }
公共字符串DelPostCode {搞定;组; }
公共字符串BilName {搞定;组; }
公共字符串BilRoad {搞定;组; }
公共字符串BilTown {搞定;组; }
公共字符串BilCity {搞定;组; }
公共字符串BilCounty {搞定;组; }
公共字符串BilPostCode {搞定;组; }
公共BOOL sameasDel {搞定;组; }
}


解决方案

显示此消息时,您要插入一些数据过大领域。



一个总理候选人这里是电子邮件 - 您只需将其设置为 15 字符,而大多数的电子邮件地址将要大得多!它提高到 255 键,然后重试。



检查所有其他人也一样,特别喜欢<$ C小的$ C>移动。


I'm getting the following error message:

string or binary data would be truncated

I've tried increasing the column size but no luck, I've doubled checked by code but cant seem to find any issues. Its during an insert:

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();

Here is my table definition code:

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)
);

Customer Class

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; }
}

解决方案

This message is shown when you are trying to insert some data that is too big for the field.

A prime candidate here is Email - you only have it set as 15 character whereas most email addresses are going to be much bigger! Increase it to 255 and try again.

Check all of the others too, especially small ones like Mobile.

这篇关于字符串或二进制数据将被截断的错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆