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

    To create a connection in ADO.NET Provider, you can use C1QuickBooksOnlineConnection class which implements two ways of creating the connection with connection string passed as an argument. You can either define the connection string as a string with all the required attributes and their values or use of the ConnectionStringBuilder class.

    The C1QuickBooksOnlineConnectionStringBuilder class can also be used to setup the connection strings to be implemented by the provider for connecting to the datasource.

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

    C#
    Copy Code
    //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 !!!");
    }