Attention
1: The column of the incoming DataTable must be the same as the table column in the database, otherwise the data will be saved by default
The 2:sql statement is intended to determine the table name as long as it is a query to the table to be inserted
3: The method to get the connection string is Getoracleconnection (), you need to add it yourself
public static bool Insertvaluewithdt (DataTable DataTable, String sql)
{
String connstr = Getoracleconnection ();
using (OracleConnection conn = new OracleConnection (CONNSTR))
{
Try
{
OracleCommand cmd = new OracleCommand (sql,conn);
OracleDataAdapter adapter = new OracleDataAdapter (cmd);
Oraclecommandbuilder cb = new Oraclecommandbuilder (adapter);
DataTable dsnew = new DataTable ();
int count = adapter. Fill (dsnew);
for (int i = 0; i < DataTable.Rows.Count; i++)
{
DataRow dr = Dsnew.newrow ();
for (int j = 0; J < DataTable.Columns.Count; J + +)
{
DR[DSNEW.COLUMNS[J]. ColumnName] = Datatable.rows[i][j];
}
DSNEW.ROWS.ADD (DR);
}
Count = adapter. Update (dsnew);
Adapter. UpdateBatchSize = 200;
Adapter. Update (dataTable);
return true;
}
catch (Exception e)
{
Writelog writelog = new Writelog ();
Writelog.writelogs (E.tostring ());
return false;
}
}
}
From: http://blog.sina.com.cn/s/blog_877c72ac010126h1.html
Save a DataTable directly in the Oracle database (GO)