Querying with the DataAdapter
The CData ADO.NET Provider for Microsoft Dynamics NAV implements two ADO.NET interfaces you can use to retrieve data from Microsoft Dynamics NAV: DynamicsNAVDataAdapter and DynamicsNAVDataReader objects. Whereas DynamicsNAVDataAdapter objects retrieve a single result set of all the data that matches a query, DynamicsNAVDataReader objects fetch data in subset increments as needed.
Using the DynamicsNAVDataAdapter
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 DynamicsNAVDataAdapter is slower than the DynamicsNAVDataReader because the Fill method needs to retrieve all data from the data source before returning.
The following example selects the No and Contact columns of the Customer table:
C#
string connectionString = "URL=http://myserver:7048;User=myserver\Administrator;Password=admin;ServerInstance=DYNAMICSNAV71;"; using (DynamicsNAVConnection connection = new DynamicsNAVConnection(connectionString)) { DynamicsNAVDataAdapter dataAdapter = new DynamicsNAVDataAdapter( "SELECT No, Contact FROM Customer", connection); DataTable table = new DataTable(); dataAdapter.Fill(table); Console.WriteLine("Contents of Customer."); foreach (DataRow row in table.Rows) { Console.WriteLine("{0}: {1}", row["No"], row["Contact"]); } }
VB.NET
Dim connectionString As String = "URL=http://myserver:7048;User=myserver\Administrator;Password=admin;ServerInstance=DYNAMICSNAV71;" Using connection As New DynamicsNAVConnection(connectionString) Dim dataAdapter As New DynamicsNAVDataAdapter("SELECT No, Contact FROM Customer", connection) Dim table As New DataTable() dataAdapter.Fill(table) Console.WriteLine("Contents of Customer.") For Each row As DataRow In table.Rows Console.WriteLine("{0}: {1}", row("No"), row("Contact")) Next End Using