如何添加所有列表框项目,但先前表中未显示的项目 [英] How to add all listbox item except those which present in table previously

查看:62
本文介绍了如何添加所有列表框项目,但先前表中未显示的项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表框.我希望单击提交时单击该按钮,然后将所有项目添加到数据库中,但以前存在于数据库中的项目除外.所有项目都带有productid和adminid,并随它们一起输入.

例如,我有管理员1的产品1,2,3,4,并且产品3已存在于管理员1的表中,然后将添加产品1,2,4,但不会添加3,因为已经为管理员1添加了产品3.

I have a list box . I want that when submit is clicked then all the items added into the database except those which present in the database previously . All the items have productid and adminid which enters with them .

For example , i have product 1,2,3,4 for admin 1 and product 3 is already present in table for admin 1 then product 1,2,4 will be added and 3 will not as it is already added for admin 1 .

推荐答案

第一,但不是最佳解决方案,您首先通过查询在表中检查它是否已保存.这很花时间.
其次,为什么不在两列上都应用复合唯一键约束..如果prodID将重复作为admin-id ..不要让它保存在数据库中并用空主体捕获异常...: )

对于第二种解决方案,您只需要通过在表上应用复合键约束来更改表结构,并且只需要在代码末尾处理带空catch块的try块中的数据库调用即可.
1st but not the best solution may be, you first check in table by query that either it is already saved or not. which is time taking.
secondly, why don''t you apply composite unique key constraint on both of the columns..that if prodID will repeat for admin-id.. do not let it save it in database and catch the exception with empty body... :)

for second solution, you require to only to make change in table structure by applying composite key constraint on table and in code end only to handle database call within try block with empty catch block.


有是我可以验证之前的类似问题一个列表框,这样我就不会重复相同的值 [

这篇关于如何添加所有列表框项目,但先前表中未显示的项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆