1,最常见的Executenonquery(返回影响的行数)sql是我的查询插入语句,你可以换成你的!这种方式入库,速度一般,大量数据时不提倡使用
1 /// <summary> 2 /// 通过table一个一个的插入 3 /// </summary> 4 /// <param name="table"></param> 5 public static void Executenonquery(DataTable table) 6 { 7 foreach (DataRow itemRow in table.Rows) 8 { 9 //if exists(select * from dbo.ID where ENG = '') 10 // begin 11 // return; 12 // end 13 //else 14 // begin 15 // INSERT INTO ID([ENG],[GB],[B5],[FILE],[MSG]) values('', '', '', '', '') 16 // end 17 string sql = "if exists(select * from " + table.TableName + " where ENG = '" + itemRow["ENG"].ToString() + "') "+ 18 " begin return; end else begin INSERT INTO " + table.TableName + "([ENG],[GB],[B5],[FILE],[MSG])" + 19 "VALUES('" + itemRow["ENG"].ToString() + "'" + 20 ",'" + itemRow["GB"].ToString() + "'" + 21 ",'" + itemRow["B5"].ToString() + "'" + 22 ",'" + itemRow["FILE"].ToString() + "'" + 23 ",'" + itemRow["MSG"].ToString() + "') end"; 24 using (SqlConnection sqlconn = new SqlConnection(connectString)) 25 { 26 sqlconn.Open(); 27 28 SqlCommand sqlcommand = new SqlCommand(sql, sqlconn); 29 sqlcommand.ExecuteNonQuery(); 30 sqlconn.Close(); 31 } 32 } 33 } 34 ————————————————