日期:2014-05-17  浏览次数:20699 次

请问下这段代码是什么意思 我看不明白 出自三层结构的DBUtility
C# code

public static void PrepareCommand(OleDbCommand cmd, OleDbConnection conn, OleDbTransaction trans, string cmdText, OleDbParameter cmdParms)
        {
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            cmd.Connection = conn;
            cmd.CommandText = cmdText;
            if (trans != null)
            {
                cmd.Transaction = trans;
            }
            cmd.CommandType = CommandType.Text;
            if (cmdParms != null)
            {
                foreach (OleDbParameter parm in cmdParms)
                {
                    cmd.Parameters.Add(parm);
                }
            }
        }




------解决方案--------------------
C# code


        /// <summary>
        /// 构建查询绑定(将cmdParms参数绑定到cmd上,将cmd的Connection设置为con,将事务trans设置到cmd上)
        /// </summary>
        /// <param name="cmd">执行对象</param>
        /// <param name="conn">连接对象</param>
        /// <param name="trans">事务对象</param>
        /// <param name="cmdText">SQL命令</param>
        /// <param name="cmdParms">执行命令的参数</param>
        public static void PrepareCommand(OleDbCommand cmd, OleDbConnection conn, OleDbTransaction trans, string cmdText, OleDbParameter cmdParms)
        {
            if (conn.State != ConnectionState.Open)
            {
                //如果没打数据库连接则打开数据库连接
                conn.Open();
            }

            //将cmd的Connection设置为con
            cmd.Connection = conn;
            //将cmd的CommandText设置为cmdText
            cmd.CommandText = cmdText;

            if (trans != null)
            {
                //将事务trans设置到cmd上
                cmd.Transaction = trans;
            }
            //执行的SQL文本,不是存储过程
            cmd.CommandType = CommandType.Text;
            if (cmdParms != null)
            {
                //将cmdParms参数绑定到cmd上
                foreach (OleDbParameter parm in cmdParms)
                {
                    cmd.Parameters.Add(parm);
                }
            }
        }

------解决方案--------------------
将参数加进Command对象
用到了事务
------解决方案--------------------
构建查询绑定(将cmdParms参数绑定到cmd上,将cmd的Connection设置为con,将事务trans设置到cmd上)
------解决方案--------------------
探讨

引用:

C# code


/// <summary>
/// 构建查询绑定(将cmdParms参数绑定到cmd上,将cmd的Connection设置为con,将事务trans设置到cmd上)
/// </summary>
/// <param name="cmd">执行对象</param>
/// <param name……

谢谢 很详细 但是我想知……

------解决方案--------------------
探讨
引用:

引用:

C# code


/// <summary>
/// 构建查询绑定(将cmdParms参数绑定到cmd上,将cmd的Connection设置为con,将事务trans设置到cmd上)
/// </summary>
/// <param name="cmd">执行对象</param>
/// <param name……

……