The ADO.NET provider for QuickBooks Online provides a wide range of features that enable connectivity to QuickBooks Online from .Net applications. The documentation will help you understand the C1.AdoNet.QuickbooksOnline namespace, which includes all the available classes that can be used to connect and retrieve data from QuickBooks Online.
DataConnectors are mostly used in combination with other ComponentOne components, such as DataEngine and FlexPivot. The procedure below describes how to use the DataConnector in a console application within Visual Studio.
The ADO.NET provider for QuickBooks Online can be used in any application. In this guide, a console application is created:
Follow the steps provided below to learn and implement data retrieval using ADO.NET provider for QuickBooks Online.
C# |
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() { try { 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); } |
C# |
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(); 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 !!!"); } |