zoukankan      html  css  js  c++  java
  • 企业库的保存方法

    /**//**//**//**//**//**//**//// <summary>        /// 数据库连接 Name 值        /// </summary>        private const string DB_CONNECTION = "CRMConnectionString";private Database _DB = null;        /**//// <summary>        /// 数据操作对象        /// </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)                {                    /**//**//**//// 两种方法都一样构造该对象                    /// string dbProviderName = ConfigurationManager.ConnectionStrings[DB_CONNECTION].ProviderName;                    /// _DBFactory = DbProviderFactories.GetFactory(dbProviderName);                    _DBFactory = DB.DbProviderFactory;                }                return _DBFactory;            }        }/**//**//**//**//**//**//**//// <summary>        /// 保存方法        /// </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.GetInsertCommand();                    Adp.UpdateCommand = Cmb.GetUpdateCommand();                    Adp.DeleteCommand = Cmb.GetDeleteCommand();                    /**//**//**//**//**//**//**//// 更新竞争对手表                    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.SelectCommand = 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();                    /**//**//**//**//**//**//**//// 更新竞争产品表                    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:#0000c0; } .csharpcode .preproc { color:#cc6633; } .csharpcode .asp { background-color:#ffff00; } .csharpcode .html { color:#800000; } .csharpcode .attr { color:#ff0000; } .csharpcode .alt { background-color:#f4f4f4; 100%; margin:0em; } .csharpcode .lnum { color:#606060; }

    E-MAIL:yiwuya@hotmail.com
    MSN:yiwuya@hotmail.com
    QQ:304899972
    纺织软件
  • 相关阅读:
    DWZ集成的xhEditor编辑器浏览本地图片上传的设置
    微服务看门神-Zuul
    OAuth2.0最简向导
    打造个人IP: 开源项目网站构建框架
    提前体验让人"回归Windows怀抱"的Windows Terminal
    ToB蓝海的台阶-PaaS,SaaS技术详解
    再不了解PostgreSQL,你就晚了之PostgreSQL主从流复制部署
    Netty实现高性能IOT服务器(Groza)之精尽代码篇中
    使用keepalived做High Available(HA)
    Nginx 常用配置方式说明
  • 原文地址:https://www.cnblogs.com/yiwuya/p/3018811.html
Copyright © 2011-2022 走看看