ExactTargetDataReader Class
Reads a forward-only stream of rows from ExactTarget.
The following example creates a
ExactTargetConnection, a
ExactTargetCommand, and a
ExactTargetDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the
ExactTargetDataReader, then the
ExactTargetConnection.
public void ReadMyData(string myConnString) {
ExactTargetConnection exactTargetConnection = new ExactTargetConnection(myConnString);
ExactTargetCommand exactTargetCommand = (ExactTargetCommand)exactTargetConnection.CreateCommand();
exactTargetCommand.CommandText = "SELECT ID, Name, Subject FROM Email";
exactTargetConnection.Open();
ExactTargetDataReader exactTargetReader = exactTargetCommand.ExecuteReader();
try {
// Always call Read before accessing data.
while (exactTargetReader.Read()) {
Console.WriteLine(exactTargetReader.GetInt32(0).ToString() + " " +
exactTargetReader.GetString(1) + " " + exactTargetReader.GetString(2));
}
}
finally {
// always call Close when done reading.
exactTargetReader.Close();
// Close the connection when done with it.
exactTargetConnection.Close();
}
}
Public Sub ReadMyData(ByVal myConnString As String)
Dim exactTargetConnection As New ExactTargetConnection(myConnString)
Dim exactTargetCommand As ExactTargetCommand = exactTargetConnection.CreateCommand()
exactTargetCommand.CommandText = "SELECT ID, Name, Subject FROM Email"
exactTargetConnection.Open()
Dim exactTargetReader As ExactTargetDataReader = exactTargetCommand.ExecuteReader()
Try
' Always call Read before accessing data.
While exactTargetReader.Read()
Console.WriteLine(String.Concat(exactTargetReader.GetInt32(0).ToString(), " ", _
exactTargetReader.GetString(1), " ", exactTargetReader.GetString(2)))
End While
Finally
' always call Close when done reading.
exactTargetReader.Close()
' Close the connection when done with it.
exactTargetConnection.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