To create a connection to QuickBooks Online, the ADO.NET Provider can be used through 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 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. Here you can query the data or request for modifications.
C# |
コードのコピー
|
---|---|
static void CreatingConn() { //接続文字列を設定します。 C1QuickBooksOnlineConnectionStringBuilder builder = new C1QuickBooksOnlineConnectionStringBuilder { OAuthClientId = OAuthClientId, OAuthClientSecret = OAuthClientSecret, OAuthTokenEndpoint = OAuthTokenEndpoint, OAuthAccessToken = OAuthAccessToken, OAuthRefreshToken = OAuthRefreshToken, CompanyId = CompanyId, UseSandbox = true }; //接続を設定します。 using (C1QuickBooksOnlineConnection conn = new C1QuickBooksOnlineConnection(builder.ConnectionString)) { conn.OAuthTokenRefreshed += OAuthTokenRefreshed; // 2 つの異なるテーブルからデータを取得しようとしました。 C1QuickBooksOnlineCommand comm = new C1QuickBooksOnlineCommand(conn, "Select * from Customers"); C1QuickBooksOnlineDataAdapter adapter = new C1QuickBooksOnlineDataAdapter(comm); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); //取得したデータを表示します。 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 !!!"); } } |