How to save the Enterprise Library

Source: Internet
Author: User
/** // <Summary> // database connection name value: // </Summary> private const string db_connection = "crmconnectionstring "; private Database _ DB = NULL; /** // <summary> // data operation object // </Summary> protected database dB {get {If (_ DB = NULL) {_ DB = databasefactory. createdatabase (db_connection);} return _ dB;} private dbproviderfactory _ dbfactory = NULL; /**//**//**//**//**//**//**//// <Summary> /// </Summary> protected dbproviderfactory dbfactory {get {If (_ dbfactory = NULL) {/** // both METHODS Construct the object // string dbprovidername = configurationmanager. connectionstrings [db_connection]. providername; // _ dbfactory = dbproviderfactories. getfactory (dbprovidername); _ dbfactory = dB. dbproviderfactory;} return _ dbfactory ;}} /** // <summary> // save Method /// </Summary> /// <Param name = "datacompany"> </param> /// <Param name = "dataproduct"> </param> // /<returns> </returns> Public bool save (datatable datacompany, datatable dataproduct) {dbcommand cmd; dbdataadapter ADP; dbcommandbuilder CMB; using (dbconnection conn = dB. createconnection () {Conn. open (); dbtransaction TRAN = NULL; try {TRAN = Conn. begintransaction (); // create the SELECT command. Cmd = dbfactory. createcommand (); cmd. commandtext = "select * From competecompany"; cmd. connection = conn; cmd. transaction = Tran; // create the dbdataadapter. ADP = dbfactory. createdataadapter (); ADP. selectcommand = cmd; // create the dbcommandbuilder. CMB = dbfactory. createcommandbuilder (); CMB. dataadapter = ADP; // get the insert, update and delete commands. ADP. insertcommand = CMB. getinsertcomm And (); ADP. updatecommand = CMB. getupdatecommand (); ADP. deletecommand = CMB. getdeletecommand (); /** // update the competition for the watch ADP. update (datacompany); // create the SELECT command. cmd = dbfactory. createcommand (); cmd. commandtext = "select * From competeproduct"; cmd. connection = conn; cmd. transaction = Tran; // create the dbdataadapter. ADP = dbfactory. createdataadapter (); ADP. selectcomm And = cmd; // create the dbcommandbuilder. CMB = dbfactory. createcommandbuilder (); CMB. dataadapter = ADP; // get the insert, update and delete commands. ADP. insertcommand = CMB. getinsertcommand (); ADP. updatecommand = CMB. getupdatecommand (); ADP. deletecommand = CMB. getdeletecommand (); /** // update the table of competing products (ADP. update (dataproduct);} catch {If (Tran. connection! = NULL) Tran. rollback () ;}finally {If (Tran. connection! = NULL) Tran. Commit () ;}return true ;}

. Csharpcode,. csharpcode pre {
Font-size: small;
Color: black;
Font-family: consolas, "Courier New", courier, monospace;
Background-color: # ffffff;
}

. Csharpcode pre {
Margin: 0em;
}

. Csharpcode. Rem {
Color: #008000;
}

. Csharpcode. kwrd {
Color: # 0000ff;
}

. Csharpcode. Str {
Color: #006080;
}

. Csharpcode. Op {
Color: # effecc0;
}

. Csharpcode. preproc {
Color: # cc6633;
}

. Csharpcode. asp {
Background-color: # FFFF00;
}

. Csharpcode. html {
Color: #800000;
}

. Csharpcode. ATTR {
Color: # ff0000;
}

. Csharpcode. Alt {
Background-color: # f4f4f4;
Width: 100%;
Margin: 0em;
}

. Csharpcode. lnum {
Color: #606060;
}

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.