1. Adding references
Using Oracle.DataAccess.Client;
Using System.Configuration;
2. Code addition method
DestinationTableName Table Name
ConnectionString Connection
String connectionString = configurationmanager.connectionstrings["defaultconnectionstring"]. ConnectionString;
Config configuration file
<add name= "defaultconnectionstring" connectionstring= "Data source= library name; User id= username; password= password; "providername=" System.Data.OracleClient "/>
DataTable data
public void Insert (string destinationtablename, String connectionString, DataTable DataTable)
{
if (DataTable.Rows.Count = = 0)
{
Return
}
String connectionString = configurationmanager.connectionstrings["defaultconnectionstring"]. ConnectionString;
String strmaintablename = "table name";
The lock table prevents concurrent production of the same batch of data that the Deduplication data table already exists
String ssqllock = "Lock table" + Strmaintablename + "in share row exclusive mode";
String strdelesqltemp = String. Format ("Delete from" + Strmaintablename + "where ny= ' {0} ' and dz in ({1})", Strdate, Stradd);
Connection
using (OracleConnection conn = new OracleConnection (connectionString))
{
int recordCount = dttemp.rows.count;//Data Bar number
Conn. Open ();//Opening connection
OracleTransaction trans = conn. BeginTransaction ();//Connect open transaction
Try
{
Lock table
OracleCommand cmdlock = new OracleCommand (Ssqllock, conn);
Cmdlock.executenonquery ();
Delete old data
OracleCommand Cmddele = new OracleCommand (STRDELESQLTEMP, conn);
Cmddele.executenonquery ();
Get the target table table structure
DataTable destdatatable = Getoracletableschema (strmaintablename);
Get INSERT statement
String strSQL = Common. Generateinsersql (Strmaintablename, Dttemp, "");
OracleCommand cmd = new OracleCommand (strSQL, conn);
Parameter assignment
Common. Generateparameter (destdatatable, dttemp, cmd);
Cmd. Transaction = trans;
Cmd. Arraybindcount = RecordCount;
Cmd. Bindbyname = true;
Cmd. ExecuteNonQuery ();
Trans.commit (); Perform
}
catch (Exception ex)
{
Trans. Rollback ();
Strretval = Common. Createxml ("0007", "error message:" + ex.) Message);
}
Finally
{
Conn. Close ();
}
}
}
Get the table column method Getoracletableschema, the parameter assignment method Generateinsersql in the blog detailed description http://www.cnblogs.com/xuxin-1989/p/4157697.html
. NET call Oracle.DataAccess.Client Bulk Add data