DataConnector | ComponentOne
ADO.NET provider for QuickBooks Online / Getting Started
In This Topic
    Getting Started
    In This Topic

    DataConnector offers many features with wide range of data connection techniques using the ADO.NET provider. This documentation helps you get started with QuickBooks Online using an ADO.NET provider by C1.DataConnector control which gives an idea about different ways of data connection.

    This quick start describes how to use QuickBooks Online ADO.NET provider provided by C1DataConnector to connect to QuickBooks online datasource. Complete the steps given below to see how QuickBooks Online 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.QuickBooksOnline 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 QuickBooks Online

    Follow the steps provided below to learn and implement data retrieval using ADO.NET provider for QuickBooks Online.

    1.  The first step is to create a reference to QuickBooks Online service URL and a platform for unlinked servers and services to allow authenticated access to the data sources without sharing private credentials using OAuth Authorization.
      Copy Code
      static string CompanyId = "*******";
      static string OAuthClientId = @"*****";
      static string OAuthClientSecret = @"******";
      static string OAuthAccessToken = @"*******";
      static string OAuthRefreshToken = @"*******";
      static string MinorVersion = "**";
      static string connectionString => $"Company Id={CompanyId};Use SandBox=true;OAuth Client Secret={OAuthClientSecret};OAuth Client Id={OAuthClientId};"         + "OAuth Access Token={OAuthAccessToken};OAuth Refresh Token={OAuthRefreshToken}; Minor Version={MinorVersion}";      
      //Set values for OAuthAccessToken and OaAuthRefreshToken
      private static void LoadAuthentication()
              var arrAuth = File.ReadAllText(@"Authentication.txt").Split(';');
              if (arrAuth[0] == CompanyId)
                  OAuthAccessToken = arrAuth[1];
                  OAuthRefreshToken = arrAuth[2];
          catch { }
      //Handle OAuthTokenRefreshed event to fetch the new access token
      private static void OAuthTokenRefreshed(object sender, EventArgs e)
          var conn = sender as C1QuickBooksOnlineConnection;
          var strAuthen = $"{conn.CompanyId};{conn.OAuthToken.AccessToken};{conn.OAuthToken.RefreshToken}";
          File.WriteAllText(@"Authentication.txt", strAuthen);
    2. In the next step, C1QuickBooksOnlineDataAdapter is used to retrieve the data. C1QuickBooksOnlineDataAdapter objects retrieve a single result set of all the data that matches a query. Click here for more information on creating connections.

      C1QuickBooksOnlineConnection implements the ADO.NET DbConnection, similar to standard ADO.NET connection object. Once the connection is established, adapter's Fill method is used to retrieve the data from the source as shown in the below code example.
      Copy Code
      //Setup Connection
      using (C1QuickBooksOnlineConnection conn = new C1QuickBooksOnlineConnection(connectionString))
          conn.OAuthTokenRefreshed += OAuthTokenRefreshed;
          //Command to fetch data from DataTable
          C1QuickBooksOnlineCommand comm = new C1QuickBooksOnlineCommand(conn, "Select * from Customers");
          C1QuickBooksOnlineDataAdapter adapter = new C1QuickBooksOnlineDataAdapter(comm);
          DataTable dataTable = new DataTable();
          //Display fetched data
          foreach (DataRow row in dataTable.Rows)
              Console.WriteLine("{0}\t{1}\t{2}", row["CompanyName"], row["DisplayName"], row["Active"]);
          Console.WriteLine("Connection created and read operation completed !!!");