DataConnector | ComponentOne
ADO.NET provider for Dynamics 365 Sales / Getting Started
In This Topic
    Getting Started
    In This Topic

    DataConnector offers everything from wide range of data connection techniques using ADO.NET provider for Dynamics 365 Sales. This documentation helps you get started with C1.DataConnector control which gives an idea about different ways of data connection and operations with Dynamics 365 Sales.

    This quick start will guide you through the steps of using DataConnector in a console application. Complete the steps given below to see how DataConnector works.

    Step 1: Create a new Console App

    1. Open Visual Studio.
    2. Select Create a new project from the Get started pane.
    3. In the Create a new project window, select Console Application and click Next.
      Create new project window
    4. In the Configure your new project window, write your project name, choose location to save your project and click Create.

    Step 2: Add the NuGet packages

    1. From the Project menu, select Manage NuGet Packages. The NuGet Package Manager appears.
    2. Select from the Package source drop down.
    3. Click Browse tab and select C1.AdoNet.D365S from the left pane.
    4. In the right pane, click Install. This adds the references for the above packages.

    Step 3: Using ADO.NET provider for Dynamics 365 Sales

    Follow the steps provided below to learn and implement data retrieval using ADO.NET provider for Dynamics 365 Sales.

    1.  The first step is to create a reference to Dynamic365 Sales service URLs and connection properties.
      const string urlDynamics = @;
      const string ClientSecret = ""
      const string clientID = "";
      const string username = "";
      const string password = "";
      const string tokenEnpoint = @"";
      const string extendProperties = @"{""resource"":""""}";
    2. In the below code exampleC1D365SConnection is used to retrieve the data. The connection string using corresponding attributes is passed as an argument. The example implements OAuth protocol for authorization. DbDataReader objects retrieve data in subset increments as required. Click here for more information on creating connections.
      //Password credential in connection string
      string connstr = $@"Url={urlDynamics};Use Cache=true;Use Etag=true;OAuth Client Id={clientID};Username={username};Password={password};OAuth Token Endpoint={tokenEnpoint};OAuth Extend Properties={extendProperties};Max Page Size = 100";
      using (var con = new C1D365SConnection(connstr))//Creating Connection using connection string as parameter
        //Open connection
        //Create Command
        var cmd = con.CreateCommand();
        cmd.CommandText = "Select  accountid, name  FROM Accounts limit 10'";
        //Executing Reader
        DbDataReader rdr = cmd.ExecuteReader();
        //Dispalaying Data using Reader Object
        while (rdr.Read())
          Console.WriteLine(String.Format("\t{0} --> \t\t{1}", rdr["accountid"], rdr["name"]));

    The following output is generated on the console application after executing the above steps.