GetDataColumn() private method

private GetDataColumn ( string sourceColumn, Type dataType, DataTable dataTable, MissingMappingAction mappingAction, MissingSchemaAction schemaAction ) : DataColumn
sourceColumn string
dataType System.Type
dataTable System.Data.DataTable
mappingAction MissingMappingAction
schemaAction MissingSchemaAction
return System.Data.DataColumn
Ejemplo n.º 1
0
 private 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(columnName, null, 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;
                     }
                 }
             }
         }
     }
 }
Ejemplo n.º 2
0
        private void ParameterInput(IDataParameterCollection parameters, StatementType typeIndex, DataRow row, DataTableMapping mappings)
        {
            Data.MissingMappingAction missingMapping = UpdateMappingAction;
            Data.MissingSchemaAction missingSchema = UpdateSchemaAction;

            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(columnName, null, row.Table, missingMapping, missingSchema);
                        if (null != dataColumn)
                        {
                            DataRowVersion version = DbDataAdapter.GetParameterSourceVersion(typeIndex, parameter);
                            parameter.Value = row[dataColumn, version];
                        }
                        else
                        {
                            parameter.Value = null;
                        }

                        DbParameter dbparameter = (parameter as DbParameter);
                        if ((null != dbparameter) && dbparameter.SourceColumnNullMapping)
                        {
                            Debug.Assert(DbType.Int32 == parameter.DbType, "unexpected DbType");
                            parameter.Value = ADP.IsNull(parameter.Value) ? s_parameterValueNullValue : s_parameterValueNonNullValue;
                        }
                    }
                }
            }
        }
Ejemplo n.º 3
0
 private DataColumn GetDataColumn(string columnName, DataTableMapping tablemapping, DataRow row) {
     DataColumn column = null;
     if (!ADP.IsEmpty(columnName)) {
         column = tablemapping.GetDataColumn(columnName, null, row.Table, _missingMappingAction, MissingSchemaAction.Error);
     }
     return column;
 }
        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;
        }
 private void ParameterOutput(IDataParameter parameter, DataRow row, DataTableMapping mappings, MissingMappingAction missingMapping, MissingSchemaAction missingSchema)
 {
     if ((ParameterDirection.Output & parameter.Direction) != ((ParameterDirection) 0))
     {
         object obj2 = parameter.Value;
         if (obj2 != null)
         {
             string sourceColumn = parameter.SourceColumn;
             if (!ADP.IsEmpty(sourceColumn))
             {
                 DataColumn column = mappings.GetDataColumn(sourceColumn, null, row.Table, missingMapping, missingSchema);
                 if (column != null)
                 {
                     if (column.ReadOnly)
                     {
                         try
                         {
                             column.ReadOnly = false;
                             row[column] = obj2;
                             return;
                         }
                         finally
                         {
                             column.ReadOnly = true;
                         }
                     }
                     row[column] = obj2;
                 }
             }
         }
     }
 }
 private void ParameterInput(IDataParameterCollection parameters, StatementType typeIndex, DataRow row, DataTableMapping mappings)
 {
     MissingMappingAction updateMappingAction = this.UpdateMappingAction;
     MissingSchemaAction updateSchemaAction = this.UpdateSchemaAction;
     foreach (IDataParameter parameter in parameters)
     {
         if ((parameter != null) && ((ParameterDirection.Input & parameter.Direction) != ((ParameterDirection) 0)))
         {
             string sourceColumn = parameter.SourceColumn;
             if (!ADP.IsEmpty(sourceColumn))
             {
                 DataColumn column = mappings.GetDataColumn(sourceColumn, null, row.Table, updateMappingAction, updateSchemaAction);
                 if (column != null)
                 {
                     DataRowVersion parameterSourceVersion = GetParameterSourceVersion(typeIndex, parameter);
                     parameter.Value = row[column, parameterSourceVersion];
                 }
                 else
                 {
                     parameter.Value = null;
                 }
                 DbParameter parameter2 = parameter as DbParameter;
                 if ((parameter2 != null) && parameter2.SourceColumnNullMapping)
                 {
                     parameter.Value = ADP.IsNull(parameter.Value) ? ParameterValueNullValue : ParameterValueNonNullValue;
                 }
             }
         }
     }
 }