//通过反射把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;
}
}
通过反射把list<T>转换成datatable,kill进程,事务传入一个Lst<String>多条sql语句
最新推荐文章于 2023-07-22 18:32:11 发布