免费邮箱 |加入收藏 | 会员中心 | 我要投稿 | RSS
您当前的位置:首页 > .NET专区 > ASP.NET应用

ado.net快速上手实践篇(一)

时间:2011-05-21 10:43:51  来源:站内  作者:潘春会

            {
                cmd = CreateDbCommd(sqlConn, trans, sqlStr, cmdType, listParams);
                result = cmd.ExecuteScalar();
                trans.Commit();
            }
            catch (Exception e)
            {
                trans.Rollback();
                throw new Exception("执行数据库操作失败, sql: " + sqlStr, e);
            }
            finally
            {
                trans.Dispose();
                CloseConnection();
            }
            return result;
        }

        public int ExecuteNonQuery(string sqlStr, CommandType cmdType, List<DbParameter> listParams)
        {
            int result = -1;
            OpenConnection();
            DbTransaction trans = sqlConn.BeginTransaction();
            try
            {
                cmd = CreateDbCommd(sqlConn, trans, sqlStr, cmdType, listParams);
                result = cmd.ExecuteNonQuery();
                trans.Commit();
            }
            catch (Exception e)
            {
                trans.Rollback();
                throw new Exception("执行数据库操作失败, sql: " + sqlStr, e);
            }
            finally
            {
                trans.Dispose();
                CloseConnection();
            }
            return result;
        }

        /// <summary>
        /// 批量插入
        /// </summary>
        /// <param name="tableName"></param>
        /// <param name="batchSize"></param>
        /// <param name="copyTimeout"></param>
        /// <param name="dt"></param>
        /// <returns></returns>
        public bool ExecuteBatchInsert(string tableName, int batchSize, int copyTimeout, DataTable dt)
        {
            bool flag = false;
            try

来顶一下
返回首页
返回首页
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表
推荐资讯
如何找出DHCP地址池里未使用的IP地址
如何找出DHCP地址池里
国内常用的DNS列表
国内常用的DNS列表
Linux邮件服务器软件比较
Linux邮件服务器软件比
学用纯CSS打造可折叠树状菜单
学用纯CSS打造可折叠树
相关文章
栏目更新
栏目热门