/// <summary> /// 导入数据测试 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button2_Click(object sender, EventArgs e) { string sql = "select * from em_script_node"; DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(int)); dt.Columns.Add("NAME", typeof(string)); dt.Columns.Add("CREATETIME", typeof(DateTime)); for (int i = 0; i < 10; i++) { DataRow dr = dt.NewRow(); dr[0] = i; dr[1] = "name is: " + i; dr[2] = DateTime.Now.AddMinutes(i); dt.Rows.Add(dr); } string tableName = "zz_0628"; int n = 0; TimeSpan ts = new TimeSpan(); using (BDBHelper dbHelper = new BDBHelper()) { //从另外一张表查询出结果再导入 //dt = dbHelper.ExecuteDataTable(sql); try { dbHelper.Drop(tableName); } catch { } if (dbHelper.TableIsExists(tableName)) { dbHelper.Drop(tableName, false); } dbHelper.CreateTableFromDataTable(tableName, dt); DateTime begin = DateTime.Now; n = dbHelper.LoadDataInDataTable(tableName, dt); ts = DateTime.Now - begin; } MessageBox.Show(string.Format("共有【{0}】条记录导入表【{1}】,用时【{2}】毫秒。", n, tableName, ts.TotalMilliseconds)); }