Use of C # built-in function RunSQL

Source: Internet
Author: User

acting on bulk execution of SQL statements An expression . RunSQL (sqlstatement,usetransaction) an expression. A variable that represents the DoCmd object.

Note: The maximum length of the SQLStatement parameter is 32,768 characters (and the maximum length of the SQL statement action parameter in the Macro window is 256 characters).

The official says it can only be used with Microsoft Access databases, but I'll test Oracle myself.

Example:

///<summary>
///Execute SQL (overloaded parameter IID from long to string)
///</summary>
///<param name= "IID" > Bulk sql Where Condition </param>
///<param name= "sqllist" >list type Sql</param>
///<param Name=" errmsg "> returned result information </param>
// <param name= "Idanew" > Database object </param>
///<returns></ Returns>
public bool Runsqls (string iid, list<string> sqllist, out string errmsg, ref idataaccess IdaN EW)
{
ErrMsg = string. Empty;
bool Breturn = false;
if (sqllist = = NULL | | sqllist.count = = 0)
{
ErrMsg = "[Runsqls ()] parameter [sqllist] is empty, no SQL executable. ";
return false;
}

Db. BeginTransaction ();
String newsql = String. Empty;
Try
{
Loop each SQL in the list
foreach (String sql in Sqllist)
{
if (sql = = string. Empty) continue;
Newsql = SQL;
if (SQL. IndexOf (": IID")! =-1)//If the parameter IID exists
{
Newsql = sql. Replace (": IID", IID.) ToString ());
}
Idanew.runsql (Newsql);//can overload parameter whether error one all rollback do not start transaction separately
Db. Execute (Newsql);
}
//db.completetransaction ();

Breturn = true;
}
catch (Exception e)
{
ErrMsg = E.message;
Commombus.info (e);
//db. Aborttransaction ();
}
return breturn;
}

Use of C # built-in function RunSQL

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.