Storing a DataTable directly in an Oracle database

Source: Internet
Author: User

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)

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.