예제 #1
0
        static public void FillTableByReader(DataTable _dt, OracleDataReader rdr)
        {
            int     i;
            DataRow _newrow;
            int     _fcount = rdr.FieldCount;

            DataTable  schemaTable      = rdr.GetSchemaTable();
            List <int> NumberColumnList = new List <int>();

            int index = 0;

            foreach (DataRow myRow in schemaTable.Rows)
            {
                _dt.Columns.Add(myRow["ColumnName"].ToString(), (Type)myRow["DataType"]);
                if ((Type)myRow["DataType"] == typeof(decimal))
                {
                    NumberColumnList.Add(index);
                }
                index++;
            }

            while (rdr.Read())
            {
                _newrow = _dt.NewRow();
                for (i = 0; i < _fcount; i++)
                {
                    if (NumberColumnList.Contains(i) && !rdr.IsDBNull(i))
                    {
                        _newrow[i] = OracleDecimal.Round(rdr.GetOracleDecimal(i), 20).Value;
                    }
                    else
                    {
                        _newrow[i] = rdr[i];
                    }
                }
                _dt.Rows.Add(_newrow);
            }
            _dt.AcceptChanges();
        }