事务队列完成大数据批量存储

private static List<int> LInts = new List<int>(); //准备队列
private static int plnum = 10;//报告当前位于队列的下标
private static int sumrows = 0; //进入队列的数据总数
private static int insnum = 10;//进入队列条数
private static int icount = 0;//入队次数
private bool SaveXsd() {
Boolean success = false;
bool add = true;
SqlConnection conn = null;
// Thread t1=new Thread(showwaitingfrom);
try {
using (TransactionScope transaction = new TransactionScope()) {
using (
conn =
new SqlConnection(ConnectionString)) {
conn.Open();
//添加订单信息
add = saveOrder(conn);
//添加订单明细
sumrows = dataGridView1.Rows.Count – 1;
icount = sumrows % insnum != 0 ? sumrows / insnum + 1 : sumrows / insnum;
for (int i = 0; i < sumrows; i++) {
LInts.Add(i);
}
// t1.Start();
int i2;
for (i2 = 0; i2 < icount – 1; i2++) {
if (!Aline(conn, add, i2, ref success))
{
//t1.Abort();
return false;
}
}
if (i2 < icount) //下标指向最后一行
{
using (TransactionScope tr = new TransactionScope()) {
plnum = LInts.Count;
if (!PLInster(conn, add, tr, ref success))
{
// t1.Abort();
return false;
}
}
}
if (conn.State != ConnectionState.Open) { conn.Open(); }
BLine(conn);
}
transaction.Complete();
// t1.Abort();
}

}

温馨提示: 此处内容需要评论本文后才能查看.

未经允许不得转载:聚艺帮 » 事务队列完成大数据批量存储

分享到:更多 ()

牛评 抢沙发

爱生活 爱设计

齐聚智慧联系我们