Mobile Big Data DBHelper

Source: Internet
Author: User

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data;usingSystem.Data.Common;usingSystem.Configuration;usingSystem.Transactions;namespacebrightdata.celldata.cityplanning.dbutility{classdbhelper:idb {String connstring= configurationmanager.connectionstrings["ConnStr"].        ConnectionString; String ProviderName= configurationmanager.connectionstrings["ConnStr"].        ProviderName; IDbCommand IDB. CreateCommand () {returnCreatedbcommand (); }        PrivateIDbCommand Createdbcommand () {returnCreatedbcommand (NULL,NULL); }        PrivateIDbCommand Createdbcommand (string[] names, object[] values) {Try{DbProviderFactory Factory=dbproviderfactories.getfactory (providerName); IDbConnection iconn=Factory.                CreateConnection (); iCONN. ConnectionString=connstring; IDbCommand Icmd=iconn.                CreateCommand (); if(Names! =NULL&& Values! =NULL)                {                     for(inti =0; I < names. Length; i++) {IDbDataParameter iparameter=Icmd.                        CreateParameter (); Iparameter.parametername=":"+Names[i]; Iparameter.value=Values[i]; Icmd.                    Parameters.Add (Iparameter); }} icmd.                Connection.Open (); returnIcmd; }            Catch(Exception ex) {System.IO.File.AppendAllText (@"D:\5.txt", ex.                Message); System.Diagnostics.Trace.WriteLine (ex.                Message); return NULL; }        }        /// <summary>        ///Add, delete, update/// </summary>        /// <param name= "SQL" ></param>        /// <returns></returns>        intIDB. ExecuteNonQuery (stringSQL) {IDbCommand Icmd=Createdbcommand (); if(Icmd! =NULL)            {                Try                {                    //using (TransactionScope SOP = new TransactionScope ())//{                    //Sop.complete (); //}Icmd.commandtext =SQL; returnIcmd.                ExecuteNonQuery (); }                Catch(Exception ex) {System.Diagnostics.Trace.WriteLine (ex).                    Message); return- About; }                finally{icmd.                Connection.close (); }            }            return- About; } IDataReader IDB. ExecuteReader (stringSQL)            {Console.WriteLine (SQL); IDbCommand Icmd=Createdbcommand (); if(Icmd! =NULL)            {                Try{Icmd.commandtext=SQL; returnIcmd.                ExecuteReader (commandbehavior.closeconnection); }                Catch(Exception ex) {System.IO.File.AppendAllText (@"D:\1.txt", ex.                    Message); System.Diagnostics.Trace.WriteLine (ex.                    Message); Icmd.                    Connection.close (); return NULL; }            }            return NULL; }        ObjectIDB. ExecuteScalar (stringSQL) {IDbCommand Icmd=Createdbcommand (); if(Icmd! =NULL)            {                Try{Icmd.commandtext=SQL; returnIcmd.                ExecuteScalar (); }                Catch(Exception ex) {System.Diagnostics.Trace.WriteLine (ex).                Message); }                finally{icmd.                Connection.close (); }            }            return NULL; }        intIDB. ExecuteNonQuery (stringSqlstring[] names,Object[] values) {IDbCommand Icmd=Createdbcommand (names, values); if(Icmd! =NULL)            {                Try{Icmd.commandtext=SQL; returnIcmd.                ExecuteNonQuery (); }                Catch(Exception ex) {System.Diagnostics.Trace.WriteLine (ex).                    Message); return- About; }                finally{icmd.                Connection.close (); }            }            return- About; } IDataReader IDB. ExecuteReader (stringSqlstring[] names,Object[] values) {IDbCommand Icmd=Createdbcommand (names, values); if(Icmd! =NULL)            {                Try{Icmd.commandtext=SQL; returnIcmd.                ExecuteReader (commandbehavior.closeconnection); }                Catch(Exception ex) {System.Diagnostics.Trace.WriteLine (ex).                    Message); Icmd.                    Connection.close (); return NULL; }            }            return NULL; }                voidIdb.setconnstring (stringconn) {connstring=Conn; }        voidIdb.setconndrive (stringDrive ) {ProviderName=Drive ; }    }}

IDB

usingSystem;usingSystem.Collections.Generic;usingSystem.Text;usingSystem.Data;namespacebrightdata.celldata.cityplanning.dbutility{ Public InterfaceIDB {intExecuteNonQuery (String sql); intExecuteNonQuery (String sql, string[] names, object[] values);        IDataReader ExecuteReader (String sql);        IDataReader ExecuteReader (String sql, string[] names, object[] values); Objectexecutescalar (String sql);        IDbCommand CreateCommand (); voidsetconnstring (String conn); voidsetconndrive (String Drive); }}
IDB Code

Mobile Big Data DBHelper

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.