表结构要相同 for (int i = 0; i < objdata.Rows.Count; i++) { insertSql = "insert into " + toTable + " values ("; for (int j = 0; j < objdata.Columns.Count ; j++) { if (j == 0) { insertSql += string.Format("'{0}'", objdata.Rows[i][j]) + ","; } else if (j > 0 && j < objdata.Columns.Count - 1) { if (objdata.Rows[i][j].GetType() == typeof(string)) { insertSql += string.Format("'{0}'", objdata.Rows[i][j]) + ","; } else { if (objdata.Rows[i][j].ToString() == "" || string.IsNullOrEmpty(objdata.Rows[i][j].ToString().Trim())) { insertSql += "0,"; } else { insertSql += objdata.Rows[i][j] + ","; } } } else if (j == objdata.Columns.Count - 1) { if (objdata.Rows[i][j].GetType() == typeof(string)) { insertSql += string.Format("'{0}'", objdata.Rows[i][j]) + ")"; } else { if (objdata.Rows[i][j].ToString() == "" || string.IsNullOrEmpty(objdata.Rows[i][j].ToString().Trim())) { insertSql += "0)"; } else { insertSql += objdata.Rows[i][j] + ")"; } } } } commm.CommandText = insertSql; commm.ExecuteNonQuery(); } MessageBox.Show("插入成功!"); } catch { throw; } finally { connn.Close(); commm.Dispose(); }