1 Replies - 1026 Views - Last Post: 11 June 2013 - 10:02 PM Rate Topic: -----

#1 jace75  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 31
  • Joined: 11-June 13

DbDataReader to DataTable Miscommunication

Posted 11 June 2013 - 06:30 PM

Attempting to load ASP DataTable using DbDataReader. Here's the code:



       //Send Select request to database
        public static DataTable ExecuteSelectCommand(string commandText) {
        DbCommand command = CreateCommand();


        //******************************************************************
        //Command text contains correct SQL procedure call to database
        //******************************************************************
        command.CommandText = commandText; 



        DataTable table;
        try {

            command.Connection.Open();



            //******************************************************************
            //Reader object HasRows returns true
            //******************************************************************
            DbDataReader reader = command.ExecuteReader();



            //******************************************************************
            //Table returns count of 0
            //******************************************************************
            table = new DataTable();
            table.Load(reader);


        }
        catch (Exception ex) {
            Utilities.LogError(ex);
            throw;
        }
        finally {
            command.Connection.Close();
        }
        return table;
    }

    //Create DbCommand object linked to database
    public static DbCommand CreateCommand() {

        //This block produces valid connection object with appropriate connection information
        DbConnection connection = DbProviderFactories.GetFactory(Configuration.DbProviderName).CreateConnection();
        connection.ConnectionString = Configuration.DbConnectionString;

        
        DbCommand command = connection.CreateCommand();
        command.CommandType = CommandType.StoredProcedure;
        return command;
    }



If anyone can help me understand the error of my thinking that this should work, it is appreciated B)/>

Is This A Good Question/Topic? 0
  • +

Replies To: DbDataReader to DataTable Miscommunication

#2 jace75  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 31
  • Joined: 11-June 13

Re: DbDataReader to DataTable Miscommunication

Posted 11 June 2013 - 10:02 PM

Solved: I sneezed, and it started working ;)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1