Querying with the DataAdapter
The CData ADO.NET Provider for NetSuite implements two ADO.NET interfaces you can use to retrieve data from NetSuite: NetSuiteDataAdapter and NetSuiteDataReader objects. Whereas NetSuiteDataAdapter objects retrieve a single result set of all the data that matches a query, NetSuiteDataReader objects fetch data in subset increments as needed.
Using the NetSuiteDataAdapter
Use the adapter's Fill method to retrieve data from the data source. An empty DataTable instance is passed as an argument to the Fill method. When the method returns, the DataTable instance is populated with the queried data. Note that the NetSuiteDataAdapter is slower than the NetSuiteDataReader because the Fill method needs to retrieve all data from the data source before returning.
The following example selects the InternalId and AcctName columns of the Account table:
C#
string connectionString = "AccountId=XABC123456;Schema=SuiteTalk;AuthScheme=Token;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;OAuthAccessToken=MyOAuthAccessToken;OAuthAccessTokenSecret=MyOAuthAccessTokenSecret;"; using (NetSuiteConnection connection = new NetSuiteConnection(connectionString)) { NetSuiteDataAdapter dataAdapter = new NetSuiteDataAdapter( "SELECT InternalId, AcctName FROM Account", connection); DataTable table = new DataTable(); dataAdapter.Fill(table); Console.WriteLine("Contents of Account."); foreach (DataRow row in table.Rows) { Console.WriteLine("{0}: {1}", row["InternalId"], row["AcctName"]); } }
VB.NET
Dim connectionString As String = "AccountId=XABC123456;Schema=SuiteTalk;AuthScheme=Token;OAuthClientId=MyOAuthClientId;OAuthClientSecret=MyOAuthClientSecret;OAuthAccessToken=MyOAuthAccessToken;OAuthAccessTokenSecret=MyOAuthAccessTokenSecret;" Using connection As New NetSuiteConnection(connectionString) Dim dataAdapter As New NetSuiteDataAdapter("SELECT InternalId, AcctName FROM Account", connection) Dim table As New DataTable() dataAdapter.Fill(table) Console.WriteLine("Contents of Account.") For Each row As DataRow In table.Rows Console.WriteLine("{0}: {1}", row("InternalId"), row("AcctName")) Next End Using