ADO.NET provider for Magento / Querying Data
Querying Data

The ADO.NET Provider for Magento implements two classes you can use to perform the Read operation: DbDataReader and C1MagentoDataAdapter classes. The tabs below describe the classes and code implementations.

Querying With DbDataReader

The DbDataReader class can be used to fetch data in subset increments as required. It can retrieve data quicker than the C1MagentoDataAdapter as it retrieves data in pages. When you read data from the DbDataReader, it requests the succeeding page from the data source to load the result, which makes the data retrieval faster.

The following code examples demonstrates a read operation from the data source using the DbDataReader and retrieves data by executing the Select command.

C#
Copy Code
static void ReadDataReader()
{
    Console.WriteLine("Read operation started !!!");
    using (C1MagentoConnection con = new C1MagentoConnection(MagentoConnectionString))
    {
      con.Open();      
      //Create Read command
      var cmd = con.CreateCommand();
      cmd.CommandText = "Select * FROM Products ";
  
      //Execute Read command and display fetched data
      var rdr = cmd.ExecuteReader();
      while (rdr.Read())
      {
          Console.WriteLine(String.Format("\\t{0} --> \\t\\t{1} --> \\t\\t{2}", rdr["Id"], rdr["Name"], rdr["Price"]));
      }
      Console.WriteLine("Read operation successful !!! \\n \\n");
    }
}