. NET call Oracle.DataAccess.Client Bulk Add data

Source: Internet
Author: User

  

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.