How to Fetch Adobe Commerce Data with a C# .NET Magento Connector
Tags: webdev, devops, csharp, tutorial
Published: 2024-05-31 14:06:17

---
canonical_url: https://developer.mescius.com/blogs/how-to-fetch-adobe-commerce-data-with-a-c-sharp-net-magento-connector
description: Learn how to fetch data from Adobe Commerce by using the ComponentOne C# .NET Magento Connector.
---
**What You Will Need**
- Visual Studio 2022
- ComponentOne Data Services Edition

**Controls Referenced**
- [C1DataConnector for Magento](https://developer.mescius.com/componentone/docs/services/online-dataconnector/magentogettingstarted.html)

**Tutorial Concept**

Learn how to fetch data from an online Adobe Commerce (also known as Magento) database and display the data within a .NET application using C#.

---
Are you looking to retrieve data from your Magento Server to build a .NET app? You’re at the right place.

As technology changes daily, there are several sources to store data, like the Magento server. Adobe provides an open-source platform named Magento that is used to create e-commerce stores and handle complex operations. If you plan to develop a .NET app using data from a Magento server, then fetching this data might seem a bit complicated. However, our [ComponentOne Data Connector](https://developer.mescius.com/componentone/net-data-service-components/data-connectors/ "https://developer.mescius.com/componentone/net-data-service-components/data-connectors/") suite features an API called [ADO.NET provider for Magento](https://developer.mescius.com/componentone/docs/services/online-dataconnector/magentogettingstarted.html "https://developer.mescius.com/componentone/docs/services/online-dataconnector/magentogettingstarted.html")**,** which offers several classes to streamline connectivity with Magento.

In this blog, we will develop a WinForms app using Magento e-commerce data. Let's break down the process into the following easy steps:

*   [Setup a WinForms App with Required Dependencies](#Setup)
*   [Fetch Data from the Magento Server](#Fetch)
*   [Create a UI and Bind It with the Fetched Magento Data](#Create)

## <a id="Setup"></a>Setup a WinForms App with Required Dependencies

Let's begin by setting up a new .NET 8 WinForms app that includes the ADO.NET Provider for Magento dependency by following these steps:

1.  Open Visual Studio and select File | New | Project to create a new WinForms app.  

![C# .NET Adobe Commerce_Configure](//cdn.mescius.io/umb/media/muejuxk5/configure.png?rmode=max&width=709&height=498)  

2.Right-click on the project in Solution Explorer and choose Manage NuGet Packages… from the context menu.  

![C# .NET Adobe Commerce_Manage Packages](//cdn.mescius.io/umb/media/sgnoynys/manage-packages.png?rmode=max&width=709&height=424)  

3.Search for [C1.AdoNet.Magento](https://www.nuget.org/packages/C1.AdoNet.Magento "https://www.nuget.org/packages/C1.AdoNet.Magento") in the NuGet Package Manager and click on Install.  

![C# .NET Adobe Commerce_Install Package](//cdn.mescius.io/umb/media/h53k2jty/install-package.png?rmode=max&width=710&height=425)

To create the app UI, we will use the input and datagrid controls from the ComponentOne WinForms suite. So, let’s add the following NuGet packages:

*   [C1.Win.InputPanel](https://www.nuget.org/packages/C1.Win.InputPanel "https://www.nuget.org/packages/C1.Win.InputPanel")
*   [C1.Win.FlexGrid](https://www.nuget.org/packages/C1.Win.FlexGrid "https://www.nuget.org/packages/C1.Win.FlexGrid")

Now that we have successfully set up the environment, the next step is to establish a connection to the Magento Server to fetch the data.

## <a id="Fetch"></a>Fetch Data from the Magento Server

To fetch the data using the C1.AdoNet.Magento API, we need to start by establishing the connection. We are using the [C1MagentoConnectionStringBuilder](https://developer.mescius.com/componentone/docs/services/online-dataconnector/C1.AdoNet.Magento~C1.AdoNet.Magento.C1MagentoConnectionStringBuilder.html "https://developer.mescius.com/componentone/docs/services/online-dataconnector/C1.AdoNet.Magento~C1.AdoNet.Magento.C1MagentoConnectionStringBuilder.html") class to create the connection string by setting its _Url_, _Username_, _Password_, and _TokenType_ properties:

```
    //Create a connection string using C1MagentoConnectionStringBuilder
    C1MagentoConnectionStringBuilder connBuilder= new C1MagentoConnectionStringBuilder();
    connBuilder.Username = @”******";
    connBuilder.Password = @"*******";
    connBuilder.TokenType= @"****";
    connBuilder.Url = @"http://****/****/****";
```

**Note:** You can pass your Magento credential in the code above.

Once the connection string is ready, let’s pass it to the [C1MagentoConnection](https://developer.mescius.com/componentone/docs/services/online-dataconnector/C1.AdoNet.Magento~C1.AdoNet.Magento.C1MagentoConnection.html "https://developer.mescius.com/componentone/docs/services/online-dataconnector/C1.AdoNet.Magento~C1.AdoNet.Magento.C1MagentoConnection.html") class to open the connection with your Magento database:

```
    //Create and establish connection
    C1MagentoConnection conn = new C1MagentoConnection(connBuilder)
    //Open connection with Database
    conn.Open();
```

**Note:** You can also check out more connection-building techniques [here](https://developer.mescius.com/componentone/docs/services/online-dataconnector/magentoconnection.html "https://developer.mescius.com/componentone/docs/services/online-dataconnector/magentoconnection.html").

Now, the connection has been made successfully with the Magento server. Let’s create an adapter using the [C1MagentoDataAdapter](https://developer.mescius.com/componentone/docs/services/online-dataconnector/C1.AdoNet.Magento~C1.AdoNet.Magento.C1MagentoDataAdapter.html "https://developer.mescius.com/componentone/docs/services/online-dataconnector/C1.AdoNet.Magento~C1.AdoNet.Magento.C1MagentoDataAdapter.html") class to retrieve the data into the DataTable based on the specified query.

```
    //Populate DataTable
    C1MagentoDataAdapter adapter = new C1MagentoDataAdapter(conn, "Select * from Products");
    DataTable dt = new DataTable();
    adapter.Fill(dt);
```

**Note:** You can also check out more data query techniques [here](https://developer.mescius.com/componentone/docs/services/online-dataconnector/magentoconnection.html "https://developer.mescius.com/componentone/docs/services/online-dataconnector/magentoconnection.html").

We have successfully fetched the data from the Magento server. Next, we will bind it with the UI to make it presentable.

## <a id="Create"></a>Create a UI and Bind It with the Fetched Magento Data

Initially, we added the FlexGrid and InputPanel packages to the project. Now, let’s place them onto the form to make a UI that aligns with the data fields. Here’s how we designed the form:

![C# .NET Adobe Commerce_Create UI](//cdn.mescius.io/umb/media/cdblnd5k/create-ui.png?rmode=max&width=739&height=431)

Let’s bind the grid and input controls with the DataTable using _DataSource_ and _DataField_ properties:

```
    c1FlexGrid1.DataSource = dt;
    inputDataNavigator1.DataSource = dt;
    inputTextBox1.DataSource = dt;
    inputTextBox1.DataField = "id";
    inputTextBox2.DataSource = dt;
    inputTextBox2.DataField = "name";
    inputTextBox3.DataSource = dt;
    inputTextBox3.DataField = "attribute_set_id";
    inputTextBox4.DataSource = dt;
    inputTextBox4.DataField = "sku";
    inputTextBox5.DataSource = dt;
    inputTextBox5.DataField = "type_id";
    inputDatePicker1.DataSource = dt;
    inputDatePicker1.DataField = "created_at";
    inputDatePicker2.DataSource = dt;
    inputDatePicker2.DataField = "updated_at";
```

That’s it! We have successfully created a WinForms app that showcases the data from the Magento server and works as shown below. You can even insert and delete records.

![DataConnectors_Magento_Sample](//cdn.mescius.io/umb/media/cnqnkwlv/dataconnectors_magento_sample.gif?rmode=max&width=749&height=439)

[Download the sample](https://cdn.mescius.io/umb/media/l35f0e2r/magentodataconnectordemo.zip) and update it with your credentials to try it out.

## Conclusion

In this blog, we showcased easy data connection techniques in .NET from the Magento server. With the data connector API, you can fetch the data from various sources like Salesforce, Kintone, and OData, among others. Explore the [Data Connector documentation](https://developer.mescius.com/componentone/docs/services/online-dataconnector/overview.html "https://developer.mescius.com/componentone/docs/services/online-dataconnector/overview.html") to learn more about these powerful APIs.