我有一个问题是要插入多行 [英] I have a problem to insert multiple rows
本文介绍了我有一个问题是要插入多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题是将一个recodrds插入数据库。
我使用的是primariykey和唯一键。
主键列是自动增量的,另一列是唯一键列。
我使用foreach循环插入记录。插入时如果有任何重复记录,则停止整个插入操作。
如果在foreach循环中出现任何重复,我想插入下一条记录。不要停止整个执行。
请帮帮我。
谢谢。
解决方案
使用try catch
for ( int i = 0 ; i < length; i ++)
{
尝试
{
// < span class =code-comment>在此处插入记录
}
catch (例外情况)
{
// 记录前
}
}
hi,
I have a problem to insert a recodrds into databse.
I am using primariykey and unique key.
Primarykey column is autoincremented, another column is unique key column.
I insert the records using foreach loop. while inserting if there is any duplicate record occur stop the entire inserting operation.
If any duplicates occur in foreach loop I want to insert next record. Dont stop entire executioin.
Please help me.
Thank you.
解决方案
use try catch
for (int i = 0; i < length; i++) { try { // insert record here } catch (Exception ex) { //log the ex } }
这篇关于我有一个问题是要插入多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文