本文介绍了更新多行插入SQL表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设有数据的String [N] [3] myData的。

Suppose there is a fully populated array of data String[n][3] myData.

我想这样做:

for (String[] row : myData)
{
   SQL = "update mytable set col3 = row[2]
   where col1 = row[0] and col2=row[1];"
}

显然,我已经留下了很多,但我想前preSS的想法尽量简洁。

Obviously I've left a lot out, but I want to express the idea as succinctly as possible.

是否有一个DB命令这样做的一个简单的方法?
怎么样不是那么简单的方法是什么?

Is there a simple way of doing this in a single DB command?How about a not so simple way?

编辑:
数据不是从其他表来(这是一个网页表单提交 - 选择题考试)

眼看因为应用程序是面向网络,它一定是注射证明。参数化查询是我的$ P $要去pferred方式。

我使用的MS-SQL Server 2005的

EDITS:Data is not coming from another table (it's a web form submission - Multiple Choice exam)
Seeing as the app is web facing, It's got to be injection proof. Parameterized Queries are my preferred way of going.
I'm using MS-SQL Server 2005

编辑:关闭,并重新要求为http://stackoverflow.com/questions/184471/multiple-db-updates

Closing, and re-asking as http://stackoverflow.com/questions/184471/multiple-db-updates

编辑:重开,因为这似乎是一个普遍的问题。

Re-opened, as this appears to be a popular question

推荐答案

如果您正在使用SQL Server,你可以使用SqlBulkCopy的。你首先必须把你的数据在一个DataTable,这将是pretty容易,因为你已经在一个字符串数组。

If you are using Sql Server you can use SqlBulkCopy. You would first have to put your data in a DataTable, which would be pretty easy since you already have it in a string array.

这篇关于更新多行插入SQL表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 22:10