[英]Insertion query C# sql server
我在此函数中有一个插入查询:
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),选择查询可以正常工作而不会出现问题。
看来问题出在,您试图在varchar列中插入太长的字符串,尝试使varchar列变大或将其更改为text列。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.