另一个插入语句与下拉列表的外键约束错误相冲突



我有一个表[软件],并有2个外键[brand_id,category_id]。我已经将2个表[品牌和类别]与下拉列表结合在一起。

当插入语句执行时,我正在获取INSERT statement conflicted with the FOREIGN KEY constraint错误。

这是代码:

Insert INTO tblSoftware(Description,Date_Of_Purchase,Price,Brand_ID,Category_ID) Values (@Description,@Date_Of_Purchase,@Price,@Brand_ID,@Category_ID)", con);   

当我从sql语句中删除brand_id和category_id时,它插入了罚款。

如何解决这个问题?

谢谢

@nexusmusic00,请确保在当时执行插入语句时,brand_id and category_id值分别存在于品牌和类别表中。

当用户没有从下拉列表中选择任何内容时,您要传递的内容。我猜您将通过0个引起问题的参数传递0,您必须将该值设置为null。

最新更新