当前位置:Gxlcms > 数据库问题 > SqlLite用SQLiteTransaction快速导入数据

SqlLite用SQLiteTransaction快速导入数据

时间:2021-07-01 10:21:17 帮助过:6人阅读

<summary> /// 导入major表数据 /// </summary> /// <param name="con"></param> /// <param name="dt"></param> public static void InsertMajor(string con, DataTable dt) { try { SQLiteConnection connection = new SQLiteConnection("data source=" + con); connection.Open(); SQLiteCommand command = connection.CreateCommand(); SQLiteTransaction transaction = connection.BeginTransaction(); #region Sql语句 command.CommandText = "INSERT OR IGNORE INTO major " + "(id," + "year," + "major," + "inter_code," + "edu_department," + "report_school ," + "subject," + "prm_level ," + "city," + "type," + "level," + "prm_major," + "prm_type," + "major_new)" + "VALUES" + "(" + "@id," + "@year," + "@major," + "@inter_code," + "@edu_department," + "@report_school ," + "@subject," + "@prm_level," + "@city," + "@type," + "@level," + "@prm_major," + "@prm_type," + "@major_new)"; #endregion #region command.Parameters.AddWithValue("@id", ""); command.Parameters.AddWithValue("@year", ""); command.Parameters.AddWithValue("@major", ""); command.Parameters.AddWithValue("@inter_code", ""); command.Parameters.AddWithValue("@edu_department", ""); command.Parameters.AddWithValue("@report_school", ""); command.Parameters.AddWithValue("@subject", ""); command.Parameters.AddWithValue("@prm_level", ""); command.Parameters.AddWithValue("@city", ""); command.Parameters.AddWithValue("@type", ""); command.Parameters.AddWithValue("@level", ""); command.Parameters.AddWithValue("@prm_major", ""); command.Parameters.AddWithValue("@prm_type", ""); command.Parameters.AddWithValue("@major_new", ""); #endregion for (int i = 0; i < dt.Rows.Count; i++) { command.Parameters["@id"].Value = dt.Rows[i]["id"].ToString(); command.Parameters["@year"].Value = dt.Rows[i]["year"].ToString(); command.Parameters["@major"].Value = dt.Rows[i]["major"].ToString(); command.Parameters["@inter_code"].Value = dt.Rows[i]["inter_code"].ToString(); command.Parameters["@edu_department"].Value = dt.Rows[i]["edu_department"].ToString(); command.Parameters["@report_school"].Value = dt.Rows[i]["report_school"].ToString(); command.Parameters["@subject"].Value = dt.Rows[i]["subject"].ToString(); command.Parameters["@prm_level"].Value = dt.Rows[i]["prm_level"].ToString(); command.Parameters["@city"].Value = dt.Rows[i]["city"].ToString(); command.Parameters["@type"].Value = dt.Rows[i]["type"].ToString(); command.Parameters["@level"].Value = dt.Rows[i]["level"].ToString(); command.Parameters["@prm_major"].Value = dt.Rows[i]["prm_major"].ToString(); command.Parameters["@prm_type"].Value = dt.Rows[i]["prm_type"].ToString(); command.Parameters["@major_new"].Value = dt.Rows[i]["major_new"].ToString(); command.ExecuteNonQuery(); } transaction.Commit(); command.Dispose(); connection.Dispose(); } catch (Exception ex) { string str = ex.ToString(); } }

 

SqlLite用SQLiteTransaction快速导入数据

标签:类库   ati   mys   summary   school   for   tab   parameter   nsa   

人气教程排行