通过反射把list<T>转换成datatable,kill进程,事务传入一个Lst<String>多条sql语句

//通过反射把list<T>转换成datatable
        public static System.Data.DataTable GetDataTable(List<ModelAnalysisData> data)
        {
            PropertyDescriptorCollection properties = TypeDescriptor.GetProperties(typeof(ModelAnalysisData));
            System.Data.DataTable dt = new System.Data.DataTable();
            for (int i = 0; i < properties.Count; i++)
            {
                PropertyDescriptor property = properties[i];
                dt.Columns.Add(property.Name, property.PropertyType);
            }
            object[] values = new object[properties.Count];
            foreach (ModelAnalysisData item in data)
            {
                for (int i = 0; i < values.Length; i++)
                {
                    values[i] = properties[i].GetValue(item);
                }
                dt.Rows.Add(values);
            }
            return dt;
        }

//计算运行时间.
Stopwatch sw = new Stopwatch();
sw.Start();
sw.Stop();
Console.WriteLine(sw.ElapsedMilliseconds);
//方法二
TimeSpan dateBegin = new TimeSpan(DateTime.Now.Ticks);
TimeSpan dateend = new TimeSpan(DateTime.Now.Ticks);
TimeSpan tspan = dateBegin.Subtract(dateend).Duration();
RadMessageBox.Show("导出成功,用时" + tspan.ToString() + "秒");

//kill进程
Process[] processes;
//获得进程的名字
processes = Process.GetProcessesByName("Excel");
if (processes.Length > 0)
{
   foreach (Process p in processes)
   {
      //kill进程
      p.Kill();
    }
}
//截取http中url的发送内容
string filename = Path.GetFileName(hlc.Request.RawUrl);
string SMS_CONTENT = HttpUtility.ParseQueryString(filename).Get(content);


        /// <summary>
        /// 创建一个 事务传入一个Lst<String>多条sql语句
        /// </summary>
        /// <param name="SqlStringList"></param>
        /// <returns></returns>
        public static int ExceSqlTran(List<string> SqlStringList)
        {
            using (OracleConnection conn = new OracleConnection(Tool.connectionString))
            {
                conn.Open();
                OracleCommand comm = new OracleCommand();
                comm.Connection = conn;
                //开始一个事务
                OracleTransaction tx = conn.BeginTransaction();
                comm.Transaction = tx;
                int  a=0;
                try
                {
                    for (int i = 0; i < SqlStringList.Count; i++)
                    {
                        string strsql = SqlStringList[i].ToString();
                        if (strsql.Trim().Length > 1)
                        {
                            comm.CommandText = strsql;
                            a= comm.ExecuteNonQuery();
                        }
                    }
                    tx.Commit();
                } 
                catch (System.Data.OracleClient.OracleException E)
                {
                    tx.Rollback();
                    throw new Exception(E.Message);
                }
                return a;
            }
        }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值