一、批量插入数据:
int times = 0;
for (int count = 0; count < dt.Rows.Count; times++)
{
for (int i = 0; i < 400 && 400 * times + i < dt.Rows.Count; i++, count++)
{
dtTemp.Rows.Add(dt.Rows[count].ItemArray);
} myDataAdapter.Update(dtTemp);
dtTemp.Rows.Clear();
}
二、批量更新数据:
public static bool MultiUpdateData(DataTable data, string Columns, string tableName)
{
using (OracleConnection connection = new OracleConnection(connectionString))
{
string SQLString = string.Format("select {0} from {1} where rownum=0", Columns, tableName);
using (OracleCommand cmd = new OracleCommand(SQLString, connection))
{
try {
connection.Open();
OracleDataAdapter myDataAdapter = new OracleDataAdapter();
myDataAdapter.SelectCommand = new OracleCommand(SQLString, connection);
OracleCommandBuilder custCB = new OracleCommandBuilder(myDataAdapter);
custCB.ConflictOption = ConflictOption.OverwriteChanges;
custCB.SetAllValues = true;
foreach (DataRow dr in data.Rows)
{
if (dr.RowState == DataRowState.Unchanged)
dr.SetModified();
}
myDataAdapter.Update(data);
data.AcceptChanges();
myDataAdapter.Dispose();
return true;
} catch (System.Data.OracleClient.OracleException E)
{
connection.Close();
return false;
}
}
}
}