我收到以下錯誤信息:字符串或二進制數據將被截斷錯誤消息
字符串或二進制數據將被截斷
我試着增加柱子大小,但沒有運氣,我已經翻了一番代碼檢查,但似乎無法找到任何問題。
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)
);
Customer類
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; }
}
嘿!歡迎來到StackOverflow。你能發佈你得到的錯誤消息嗎?如果可能的話,導致錯誤的'客戶'對象的一些示例值? –
您可以發佈Customer對象中的值嗎? –
我得到的錯誤是標題中的錯誤,它出現在ExecuteNonQuery中。客戶是類似於會話的類;客戶客戶=(客戶)會話[「訂單」]; - 客戶類別位於主文章 – user3607626