DataConnector | ComponentOne
ADO.NET provider for QuickBooks Online / Schema Details
In This Topic
    Schema Details
    In This Topic

     

    The ADO.NET provider for QuickBooks Online supports schema discovery using ADO.NET classes.  This is done through the GetSchema method of the  C1QuickBooksOnlineConnection class which is used to retrieve schema of the Database and DataTables. 

    In the following code example, the ReadOperation method demonstrates schema discovery using the ADO.NET provider for QuickBooks Online. The GetSchema method is used to retrieve information about the tables in the QuickBooks Online database. The code iterates over the rows of the databaseTables DataTable to display the names of the tables.

    The ToCSV extension method is used to convert the dtColumnsSchema DataTable to a CSV file and save it to a specified path. This method writes the DataTable's contents to a StreamWriter, ensuring that the values are properly formatted and enclosed in quotes if necessary.

    The CsvHelper static class defines the ToCSV extension method, which takes a DataTable and a file path as input and writes the DataTable's contents to a CSV file.

    Note: The data model information used in the following code is fetched from our account based on the available permissions. Similarly, you can write the code to get your data model information based on your requirements and account permissions.
    C#
    Copy Code
    class Program
    {
        const string CompanyId = "*******";
        const string OAuthClientId = @"*****";
        const string OAuthClientSecret = @"******";
        const string OAuthAccessToken = @"*******";
        const string OAuthRefreshToken = @"*******";
        const string OAuthTokenEndpoint = @"*******";
        const string MinorVersion = "**";
    
        static string connectionString = $"Url=https://sandbox-quickbooks.api.intuit.com;Company Id={CompanyId};Use SandBox=true;OAuth Client Secret={OAuthClientSecret};OAuth Client Id={OAuthClientId};" +
                        $"OAuth Access Token={OAuthAccessToken};OAuth Refresh Token={OAuthRefreshToken}; OAuth Token Endpoint={OAuthTokenEndpoint};Minor Version={MinorVersion}";
    
        static void Main(string[] args)
        {
            ReadOperation();
        }
    
        static void ReadOperation()
        {
            using (var conn = new C1QuickBooksOnlineConnection(connectionString))
            {
                conn.Open();
    
                DataTable databaseTables = conn.GetSchema("Tables");
                Console.WriteLine("List of Tables in database: \n");
                foreach (DataRow row in databaseTables.Rows)
                {
                    //Display table names
                    string tableName = row["TableName"].ToString();
                    Console.WriteLine(tableName);//Table Name
    
                    //Get column names in a table
                    DataTable dtColumnsSchema = conn.GetSchema("Columns", new string[] { tableName });
    
                    //Remove column DbType
                    dtColumnsSchema.Columns.Remove("DbType");
    
                    //Add column References
                    var fkCol = dtColumnsSchema.Columns.Add();
                    fkCol.ColumnName = "References";
    
                    //Populate data for column References
                    DataTable dtForignKeys = conn.GetSchema("foreignkeys", new string[] { tableName });
    
                    foreach (DataRow fkRow in dtForignKeys.Rows)
                    {
                        //Name of the column that is a foreign key
                        var fkColName = fkRow["ColumnName"];
    
                        //Find corresponding data row in dtColumnsSchema
                        var dtRow = dtColumnsSchema.Rows.Cast<DataRow>().Where(r => r["ColumnName"].ToString().Equals(fkColName)).Select(r => r).First();
    
                        //Fill value
                        dtRow["References"] = $"{fkRow["ForeignKeyTableName"]}.{fkRow["ForeignKeyColumnName"]}";
                    }
                    dtColumnsSchema.ToCSV($@"E:\temp\QuickBooksOnline\{tableName}.csv");
                }
            }
        }
    }
    
    static class CsvHelper
    {
        public static void ToCSV(this DataTable dtDataTable, string strFilePath)
        {
            using (StreamWriter sw = new StreamWriter(strFilePath, false))
            {
                //headers   
                for (int i = 0; i < dtDataTable.Columns.Count; i++)
                {
                    sw.Write(dtDataTable.Columns[i]);
                    if (i < dtDataTable.Columns.Count - 1)
                    {
                        sw.Write(",");
                    }
                }
                sw.Write(sw.NewLine);
    
                foreach (DataRow dr in dtDataTable.Rows)
                {
                    for (int i = 0; i < dtDataTable.Columns.Count; i++)
                    {
                        if (!Convert.IsDBNull(dr[i]))
                        {
                            string value = dr[i].ToString();
                            if (value.Contains(','))
                            {
                                value = String.Format("\"{0}\"", value);
                                sw.Write(value);
                            }
                            else
                            {
                                sw.Write(dr[i].ToString());
                            }
                        }
                        if (i < dtDataTable.Columns.Count - 1)
                        {
                            sw.Write(",");
                        }
                    }
                    sw.Write(sw.NewLine);
                }
                sw.Close();
            }
        }
    }

    Alternatively to the GetSchema method, the GetSchemaTable method of the C1DataReader class can be used, which returns a DataTable with the definitions of the column metadata.

    Static Schema Details

    The ADO.NET provider models the data in QuickBooks Online into a list of tables that can be queried using standard SQL statements. Following is the list of ADO.NET Provider for QuickBooks Online Tables.

    Table Name Description
    Accounts Create, update, and query QuickBooks Accounts.
    Attachables Attachables
    BillPayments Create, update, delete, and query QuickBooks Bill Payments.
    Bills Create, update, delete, and query QuickBooks Bills.
    Budgets Query QuickBooks Budgets.
    Class Create, update, delete, and query QuickBooks Classes.
    CompanyCurrency Create, update and query QuickBooks CompanyCurrency. Applicable only for those companies that enable multicurrency, a companycurrency object defines a currency that is active in the QuickBooks Online company. One or more companycurrency objects are active based on the company's multicurrency business requirements and correspond to the list displayed by the Currency Center in the QuickBooks Online UI.
    CompanyInfo Retrieve information about the QuickBooks company.
    CreditCardPayments Query QuickBooks Credit Card Payments.
    CreditMemos Create, update, delete, and query QuickBooks Credit Memos.
    Customers Create, update, and query QuickBooks Customers.
    CustomerTypes Query QuickBooks Customer Types.
    Departments Create, update and query QuickBooks Departments.
    Deposits Create, update, delete, and query QuickBooks Deposits.
    Employees Create, update and query QuickBooks Employees.
    Entitlements Retrieves QuickBooks Entitlements.
    Estimates Create, update, delete, and query QuickBooks Estimates.
    ExchangeRates Retrieves QuickBooks exchange rates.
    Invoices Create, update, delete, and query QuickBooks Invoices.
    Items Create, update, and query QuickBooks Items.
    JournalCode Create, update, delete, and query QuickBooks Journal Codes.
    JournalEntries Create, update, delete, and query QuickBooks Journal Entries.
    PaymentMethods Create, update, and query QuickBooks Payment Methods.
    Payments Create, update, delete, and query QuickBooks Payments.
    Preferences Query QuickBooks Preferences. The Preferences table contains settings for company-wide preferences, which affect all users.
    PurchaseOrders Create, update, delete, and query QuickBooks Purchase Orders.
    Purchases Create, update, delete, and query QuickBooks Purchases.
    RefundReceipts Create, update, delete, and query QuickBooks RefundReceipts.
    SalesReceipts Create, update, delete, and query QuickBooks Sales Receipts.
    TaxAgency Create and Query QuickBooks Tax Agency.
    TaxClassifications Query QuickBooks Tax Classification.
    TaxCodes Query QuickBooks Sales Tax Codes.
    TaxPayments Query QuickBooks Tax Payment. Applicable for AU and UK locales only.
    TaxRates Query QuickBooks Tax Rates.
    Terms Create, update, and query QuickBooks Terms.
    TimeActivities Create, update, delete, and query QuickBooks Time Activities.
    Transfers Create, update, delete, and query QuickBooks Transfers
    VendorCredits Create, update, delete, and query QuickBooks Vendor Credits.
    Vendors Create, update, delete, and query QuickBooks Vendors.