【发布时间】:2013-05-08 23:14:17
【问题描述】:
我在这个函数中有一个插入查询:
public string Insert_Piece(List<Piece> liste)
{
this.Connect();
using (connexion)
{
using (SqlCommand sqlCmd = new SqlCommand("INSERT INTO Piece (IDPiece, IDSuperlot, Url) VALUES (@idpiece, @idsuperlot, @url)", connexion))
{
foreach (Piece p in liste)
{
sqlCmd.Parameters.AddWithValue("@idpiece", p.Id_piece);
sqlCmd.Parameters.AddWithValue("@idsuperlot", p.Id_super_lot);
sqlCmd.Parameters.AddWithValue("@url", p.Url_piece);
try
{
sqlCmd.ExecuteNonQuery();
}
catch (Exception e) { return e.ToString(); }
}
return "cava";
}
}
}
但总是出现异常:
我不知道是什么问题以及如何解决它。 3 个属性是字符串(varchar),选择查询可以正常工作。
- 怎么了?
- 我该如何解决?
【问题讨论】:
-
你能把错误翻译成英文吗,那会很有帮助的。
-
我认为是“字符串或二进制数据将被截断”
-
因此,您的一个字符串对于您尝试将其插入的列来说太长了(可能是 URL)
标签: c# .net sql sql-server wpf