SalesforceDataReader Class
Reads a forward-only stream of rows from Salesforce.com or Database.com.
The following example creates a
SalesforceConnection, a
SalesforceCommand, and a
SalesforceDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the
SalesforceDataReader, then the
SalesforceConnection.
public void ReadMyData(string myConnString)
{
string mySelectQuery = "SELECT ID, Name FROM Account";
SalesforceConnection salesforceConnection = new SalesforceConnection(myConnString);
SalesforceCommand salesforceCommand = new SalesforceCommand(mySelectQuery,salesforceConnection);
salesforceConnection.Open();
SalesforceDataReader salesforceReader;
salesforceReader = salesforceCommand.ExecuteReader();
// Always call Read before accessing data.
while (salesforceReader.Read()) {
Console.WriteLine(salesforceReader.GetString(0) + ", " + salesforceReader.GetString(1));
}
// always call Close when done reading.
salesforceReader.Close();
// Close the connection when done with it.
salesforceConnection.Close();
}
Public Sub ReadMyData(myConnString As String)
Dim mySelectQuery As String = "SELECT ID, Name FROM Account"
Dim salesforceConnection As New SalesforceConnection(myConnString)
Dim salesforceCommand As New SalesforceCommand(mySelectQuery, salesforceConnection)
salesforceConnection.Open()
Dim salesforceReader As SalesforceDataReader
salesforceReader = salesforceCommand.ExecuteReader()
' Always call Read before accessing data.
While salesforceReader.Read()
Console.WriteLine(salesforceReader.GetString(0) & ", " & salesforceReader.GetString(1))
End While
' always call Close when done reading.
salesforceReader.Close()
' Close the connection when done with it.
salesforceConnection.Close()
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