The ADO.NET provider for Magento provides a wide range of features that enable connectivity to Magento from .Net applications. The documentation will help you understand the C1.AdoNet.Magento namespace, which includes all the available classes that can be used to connect and retrieve data from a Magento service.
DataConnectors are mostly used in combination with other ComponentOne components, such as DataEngine and FlexPivot. The procedure below describes how to use the DataConnector in a console application within Visual Studio.
The ADO.NET provider for Magento can be used in any application. In this guide, a console application is created:
To use the ADO.NET provider for Magento in an application, the respective NuGet package should be added:
Follow the steps provided below to learn and implement data retrieval using ADO.NET provider for Magento.
C# |
コードのコピー
|
---|---|
//接続文字列を定義します。 string connectionString = @"Url = http://****/****/****, Username= yourusername; Password= yourpassword; Token Type= TokenType; |
Fetch the data using C1MagentoConnection class. The connection string using corresponding attributes is passed as an argument. For more information on creating connections, see Creating Connection. C1MagentoConnection implements the ADO.NET DbConnection, similar to standard ADO.NET connection object that retrieves a single result set of all the data that matches a query. Once the connection is established, it retrieves the data from the source as shown in the following code example.
C# |
コードのコピー
|
---|---|
using (C1MagentoConnection conn = new C1MagentoConnection(MagentoConnection)) { //DataTable を設定します。 C1MagentoDataAdapter adapter = new C1MagentoDataAdapter(conn, "Select id, name, price, visibility from products"); DataTable dataTable = new DataTable(); var i = adapter.Fill(dataTable); if (i != -1) { //取得したデータを表示します。 foreach (DataRow row in dataTable.Rows) { Console.WriteLine("Product Id:{0}", row["id"]); Console.WriteLine("Product Name:{0}", row["name"]); Console.WriteLine("Price:{0}", row["price"]); Console.WriteLine("Visibility:{0}", row["visibility"]); Console.WriteLine("\n"); } Console.WriteLine("Read operation successful !!! \n \n"); } } |
The following output is generated on the console application on executing the above steps.