gpt4 book ai didi

c# - 字符串或二进制数据将被截断。?

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

我正在 C# 网络应用程序中构建输入表单。我可以很好地提交它,但我收到了 System.Data.SqlClient.SqlException (0x80131904): String or binary data would be truncated 错误。我知道这是一个长度问题,但我仔细检查了所有内容,但似乎无法在这里解决这个问题。

{
// Open Connection
thisConnection.Open();

// Create INSERT statement with named parameters
nonqueryCommand.CommandText = "INSERT INTO InventoryInput (Date, Item, Qty, WStatus) VALUES (@Date, @Qty, @Item, @WStatus)";


// Add Parameters to Command Parameters collection
nonqueryCommand.Parameters.Add("@Date", System.Data.SqlDbType.DateTime);
nonqueryCommand.Parameters.Add("@Item", System.Data.SqlDbType.VarChar, 255);
nonqueryCommand.Parameters.Add("@QTY", System.Data.SqlDbType.NChar, 10);
nonqueryCommand.Parameters.Add("@WStatus", System.Data.SqlDbType.VarChar, 50);


nonqueryCommand.Parameters["@Date"].Value = TextBox1.Text;
nonqueryCommand.Parameters["@Item"].Value = DropDownList1.Text;
nonqueryCommand.Parameters["@QTY"].Value = TextBox2.Text;
nonqueryCommand.Parameters["@WStatus"].Value = DropDownList3.Text;
nonqueryCommand.ExecuteNonQuery();

}

enter image description here

最佳答案

您混淆了两个列:

(Date,  Item, Qty,   WStatus) VALUES
(@Date, @Qty, @Item, @WStatus)

您正在尝试将 @Qty 插入到 Item 列(好的),并将 @Item 插入到 Qty 列(可能是错误的)。

我也同意一些数据类型看起来仍然可疑的评论——例如一个非数字数量。

关于c# - 字符串或二进制数据将被截断。?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12037875/

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