DataConnector | ComponentOne
ADO.NET provider for QuickBooks Online / Creating Connection
In This Topic
    Creating Connection
    In This Topic

    To create a connection to QuickBooks Online, the ADO.NET Provider can be used through the C1QuickBooksOnlineConnection class. This class requires a connection string to be provided as an argument, which can be created in either of the following ways:

    The following code shows how the C1QuickBooksOnlineConnectionStringBuilder class can be used to configure the connection string for QuickBooks Online and consumed by the C1QuickBooksOnlineConnection class to create a connection to QuickBooks Online server. Here you can query the data or request modifications.

    C#
    Copy Code
    static void CreatingConn()
    {           
        //Configure Connection string
        C1QuickBooksOnlineConnectionStringBuilder builder = new C1QuickBooksOnlineConnectionStringBuilder
        {
            OAuthClientId = OAuthClientId,
            OAuthClientSecret = OAuthClientSecret,
            OAuthTokenEndpoint = OAuthTokenEndpoint,
            OAuthAccessToken = OAuthAccessToken,
            OAuthRefreshToken = OAuthRefreshToken,
            CompanyId = CompanyId,
            UseSandbox = true
        };
    
        //Setup Connection
        using (C1QuickBooksOnlineConnection conn = new C1QuickBooksOnlineConnection(builder.ConnectionString))
        {
            
            conn.OAuthTokenRefreshed += OAuthTokenRefreshed;
    
            //Tried fetching data from two different tables
            C1QuickBooksOnlineCommand comm = new C1QuickBooksOnlineCommand(conn, "Select * from Customers");
    
            C1QuickBooksOnlineDataAdapter adapter = new C1QuickBooksOnlineDataAdapter(comm);
            DataTable dataTable = new DataTable();
            adapter.Fill(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 !!!");
        }
    }