public static void ParameterInput(MissingMappingAction missingMapping, MissingSchemaAction missingSchema, IDataParameterCollection parameters, StatementType typeIndex, DataRow row, DataTableMapping mappings)
        {
            foreach (IDataParameter parameter in parameters)
            {
                if ((null != parameter) && (0 != (ParameterDirection.Input & parameter.Direction)))
                {
                    string columnName = parameter.SourceColumn;
                    if (!string.IsNullOrEmpty(columnName))
                    {
                        DataColumn dataColumn = mappings.GetDataColumn(sourceColumn: columnName, dataType: null, dataTable: row.Table, missingMapping, missingSchema);
                        if (null != dataColumn)
                        {
                            DataRowVersion version = GetParameterSourceVersion(typeIndex, parameter);
                            parameter.Value = row[dataColumn, version];
                        }
                        else
                        {
                            parameter.Value = null;
                        }

                        if (parameter is DbParameter p2 && p2.SourceColumnNullMapping)
                        {
                            Debug.Assert(DbType.Int32 == parameter.DbType, "unexpected DbType");
                            parameter.Value = Utility.IsNull(parameter.Value) ? ParameterValueNullValue : ParameterValueNonNullValue;
                        }
                    }
                }
            }
        }
 public static void ParameterOutput(IDataParameter parameter, DataRow row, DataTableMapping mappings, MissingMappingAction missingMapping, MissingSchemaAction missingSchema)
 {
     if (0 != (ParameterDirection.Output & parameter.Direction))
     {
         object value = parameter.Value;
         if (null != value)
         {
             // null means default, meaning we leave the current DataRow value alone
             string columnName = parameter.SourceColumn;
             if (!string.IsNullOrEmpty(columnName))
             {
                 DataColumn dataColumn = mappings.GetDataColumn(sourceColumn: columnName, dataType: null, dataTable: row.Table, missingMapping, missingSchema);
                 if (null != dataColumn)
                 {
                     if (dataColumn.ReadOnly)
                     {
                         try
                         {
                             dataColumn.ReadOnly = false;
                             row[dataColumn]     = value;
                         }
                         finally
                         {
                             dataColumn.ReadOnly = true;
                         }
                     }
                     else
                     {
                         row[dataColumn] = value;
                     }
                 }
             }
         }
     }
 }
示例#3
0
        private int Fill(DataTable dataTable, DataTableMapping tableMapping, IDataReader dataReader, int startRecord, int maxRecords)
        {
            int rowsAffected = 0;
            int rowIndex     = 0;

            dataTable.BeginLoadData();

            try
            {
                while (dataReader.Read() && ((rowsAffected < maxRecords) || maxRecords <= 0))
                {
                    if (rowIndex >= startRecord)
                    {
                        DataRow row = dataTable.NewRow();

                        for (int index = 0; index < dataReader.FieldCount; index++)
                        {
                            string     name      = dataReader.GetName(index);
                            Type       fieldType = dataReader.GetFieldType(index);
                            DataColumn column    = tableMapping.GetDataColumn(name, fieldType, dataTable, MissingMappingAction, MissingSchemaAction);

                            if (column != null)
                            {
                                if (dataTable.Columns.Contains(column.ColumnName))
                                {
                                    row[column] = dataReader.GetValue(index);
                                }
                            }
                        }

                        dataTable.Rows.Add(row);
                        row.AcceptChanges();
                        rowsAffected++;
                    }

                    rowIndex++;
                }
            }
            finally
            {
                dataTable.EndLoadData();
            }

            return(rowsAffected);
        }