I have an insertion query in this function :
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";
}
}
}
But always an exception appears:
I don't know what is the problem and how can i fix it . The 3 attributs are string (varchar) and the selection queries works fine without problem.
- What is the matter?
- How can i fix it?