Reads a forward-only stream of rows from Dynamics 365.
The following example creates a
DynamicsConnection, a
DynamicsCommand, and a
DynamicsDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the
DynamicsDataReader, then the
DynamicsConnection.
public void ReadMyData(string myConnString) {
DynamicsConnection dynamicsConnection = new DynamicsConnection(myConnString);
DynamicsCommand dynamicsCommand = (DynamicsCommand)dynamicsConnection.CreateCommand();
dynamicsCommand.CommandText = "SELECT contactid, firstname, lastname FROM contact";
dynamicsConnection.Open();
DynamicsDataReader dynamicsReader = dynamicsCommand.ExecuteReader();
try {
// Always call Read before accessing data.
while (dynamicsReader.Read()) {
Console.WriteLine(dynamicsReader.GetGuid(0).ToString() + " " +
dynamicsReader.GetString(1) + " " + dynamicsReader.GetString(2));
}
}
finally {
// always call Close when done reading.
dynamicsReader.Close();
// Close the connection when done with it.
dynamicsConnection.Close();
}
}
Public Sub ReadMyData(ByVal myConnString As String)
Dim dynamicsConnection As New DynamicsConnection(myConnString)
Dim dynamicsCommand As DynamicsCommand = dynamicsConnection.CreateCommand()
dynamicsCommand.CommandText = "SELECT contactid, firstname, lastname FROM contact"
dynamicsConnection.Open()
Dim dynamicsReader As DynamicsDataReader = dynamicsCommand.ExecuteReader()
Try
' Always call Read before accessing data.
While dynamicsReader.Read()
Console.WriteLine(String.Concat(dynamicsReader.GetGuid(0).ToString(), " ", _
dynamicsReader.GetString(1), " ", dynamicsReader.GetString(2)))
End While
Finally
' always call Close when done reading.
dynamicsReader.Close()
' Close the connection when done with it.
dynamicsConnection.Close()
End Try
End Sub
Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2