private void BuildCache(bool closeConnection)
        {
            OracleCommand sourceCommand = SourceCommand;

            if (sourceCommand == null)
            {
                throw new InvalidOperationException("The DataAdapter.SelectCommand property needs to be initialized.");
            }
            OracleConnection connection = sourceCommand.Connection;

            if (connection == null)
            {
                throw new InvalidOperationException("The DataAdapter.SelectCommand.Connection property needs to be initialized.");
            }

            if (dbSchemaTable == null)
            {
                if (connection.State == ConnectionState.Open)
                {
                    closeConnection = false;
                }
                else
                {
                    connection.Open();
                }

                OracleDataReader reader = sourceCommand.ExecuteReader(CommandBehavior.SchemaOnly | CommandBehavior.KeyInfo);
                dbSchemaTable = reader.GetSchemaTable();
                reader.Close();
                if (closeConnection)
                {
                    connection.Close();
                }
                BuildInformation(dbSchemaTable);
            }
        }
示例#2
0
        ///    <summary>
        /// Converts a NpgsqlDataReader to a DataSet
        ///    <param name='reader'>
        /// NpgsqlDataReader to convert.</param>
        ///    <returns>
        /// DataSet filled with the contents of the reader.</returns>
        ///    </summary>
        public static DataSet ConvertDataReaderToDataSet(OracleDataReader reader, string tabela)
        {
            DataSet dataSet = new DataSet();
            do
            {
                // Create new data table

                DataTable schemaTable = reader.GetSchemaTable();
                DataTable dataTable = new DataTable(tabela);

                if (schemaTable != null)
                {
                    // A query returning records was executed

                    for (int i = 0; i < schemaTable.Rows.Count; i++)
                    {
                        DataRow dataRow = schemaTable.Rows[i];
                        // Create a column name that is unique in the data table
                        string columnName = (string)dataRow["ColumnName"]; //+ "<C" + i + "/>";
                        // Add the column definition to the data table
                        DataColumn column = new DataColumn(columnName, (Type)dataRow["DataType"]);
                        dataTable.Columns.Add(column);
                    }

                    dataSet.Tables.Add(dataTable);

                    // Fill the data table we just created

                    while (reader.Read())
                    {
                        DataRow dataRow = dataTable.NewRow();

                        for (int i = 0; i < reader.FieldCount; i++)
                            dataRow[i] = reader.GetValue(i);

                        dataTable.Rows.Add(dataRow);
                    }
                }
                else
                {
                    // No records were returned

                    DataColumn column = new DataColumn("RowsAffected");
                    dataTable.Columns.Add(column);
                    dataSet.Tables.Add(dataTable);
                    DataRow dataRow = dataTable.NewRow();
                    dataRow[0] = reader.RecordsAffected;
                    dataTable.Rows.Add(dataRow);
                }
            }
            while (reader.NextResult());
            return dataSet;
        }
示例#3
0
 public override System.Data.DataTable GetSchemaTable()
 {
     return(rdr.GetSchemaTable());
 }