private string GetInsertSql(SqlDataReader reader, TargetTableSheet sheet) { var fields = new StringBuilder(); var values = new StringBuilder(); fields.AppendFormat("[{0}]", sheet.Columns[0].Name); values.Append(DataUtility.GetSqlValue(reader, 0)); for (int i = 1; i < sheet.Columns.Count; i++) { fields.AppendFormat(", [{0}]", sheet.Columns[i].Name); if (i == 8) { values.Append(", '" + GetDates(reader[i].ToString()) + "'"); } else { values.Append(", " + DataUtility.GetSqlValue(reader, i)); } } var sql = new StringBuilder(); sql.AppendLine(string.Format("INSERT INTO [{0}$] ({1})", sheet.Name, fields.ToString())); sql.AppendLine(string.Format("SELECT {0}", values.ToString())); return(sql.ToString()); }
private string GetInsertSql(SqlDataReader reader, TargetTableSheet sheet, List <string> cols) { var fields = new StringBuilder(); var values = new StringBuilder(); fields.AppendFormat("[{0}]", cols[0]); values.Append(DataUtility.GetSqlValue(reader, 0)); for (int i = 1; i < cols.Count; i++) { fields.AppendFormat(", [{0}]", cols[i]); values.Append(", " + DataUtility.GetSqlValue(reader, i)); } var sql = new StringBuilder(); sql.AppendLine(string.Format("INSERT INTO [{0}$] ({1})", sheet.Name, fields.ToString())); sql.AppendLine(string.Format("SELECT {0}", values.ToString())); return(sql.ToString()); }
private string GetInsertSql(OleDbDataReader reader, int importId, string suffix, int columnCount, string columns, string columns2, object values2) { var values = new StringBuilder(); values.Append(DataUtility.GetSqlValue(reader, 0)); for (int i = 1; i < columnCount; i++) { values.Append(", " + DataUtility.GetSqlValue(reader, i)); } string values2s = values2 == null ? "" : values2.ToString(); var sql = ""; if (string.IsNullOrEmpty(columns2) || string.IsNullOrEmpty(values2s.ToString())) { sql = string.Format("INSERT INTO Import{0} (ImportId, {2}) VALUES ({1}, {3})", suffix, importId, columns, values); } else { sql = string.Format("INSERT INTO Import{0} (ImportId, {2}, {4}) VALUES ({1}, {3}, {5})", suffix, importId, columns, values, columns2, values2s); } return(sql); }