public DBRowCollection GetData(string selectStatement, string keyColumn) { var dataOut = new DBRowCollection(); var dataTable = GetDataTable(selectStatement); foreach (DataRow row in dataTable.Rows) { try { var newDataRow = new DBFieldCollection(); foreach (DataColumn column in dataTable.Columns) { if (!column.ColumnName.Equals(keyColumn, StringComparison.InvariantCultureIgnoreCase)) { newDataRow.Add(column.ColumnName, row[column.ColumnName].ToString()); } } dataOut.Add(row[keyColumn].ToString(), newDataRow); } catch (Exception ex) { throw new ApplicationException(string.Format("The file {0} was already found in the dataset. Please ensure the database is returning distinct filenames.", row[keyColumn].ToString())); } } return(dataOut); }
public static SPDataRecord ToSPDataRecord(this DBFieldCollection fieldData, SPColumnMappings mapping, string keyValue) { var dataRecordOut = new SPDataRecord(keyValue); foreach (SPColumnMapping item in mapping) { var spfield = new SPDataField(); spfield.SPColumnInternalName = item.SharePointDestinationField; spfield.SPDataType = item.SharePointDataType; try { spfield.SPValue = fieldData[item.DBSourceField].ToString(); } catch { spfield.SPValue = string.Empty; } dataRecordOut.Add(spfield); } return(dataRecordOut); }
public DBRowCollection GetData(string selectStatement, string keyColumn) { var dataOut = new DBRowCollection(); var dataTable = GetDataTable(selectStatement); foreach (DataRow row in dataTable.Rows) { try { var newDataRow = new DBFieldCollection(); foreach (DataColumn column in dataTable.Columns) { if (!column.ColumnName.Equals(keyColumn, StringComparison.InvariantCultureIgnoreCase)) newDataRow.Add(column.ColumnName, row[column.ColumnName].ToString()); } dataOut.Add(row[keyColumn].ToString(), newDataRow); } catch (Exception ex) { throw new ApplicationException(string.Format("The file {0} was already found in the dataset. Please ensure the database is returning distinct filenames.", row[keyColumn].ToString())); } } return dataOut; }