Reads a forward-only stream of rows from Adobe Commerce.
The following example creates a
MagentoConnection, a
MagentoCommand, and a
MagentoDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the
MagentoDataReader, then the
MagentoConnection.
|
|---|
public void ReadMyData(string myConnString) {
MagentoConnection magentoConnection = new MagentoConnection(myConnString);
MagentoCommand magentoCommand = (MagentoCommand)magentoConnection.CreateCommand();
magentoCommand.CommandText = "SELECT customer_id, firstname, lastname FROM Customers";
magentoConnection.Open();
MagentoDataReader magentoReader = magentoCommand.ExecuteReader();
try {
// Always call Read before accessing data.
while (magentoReader.Read()) {
Console.WriteLine(magentoReader.GetInt32(0).ToString() + " " +
magentoReader.GetString(1) + " " + magentoReader.GetString(2));
}
}
finally {
// always call Close when done reading.
magentoReader.Close();
// Close the connection when done with it.
magentoConnection.Close();
}
} |
|
|---|
Public Sub ReadMyData(ByVal myConnString As String)
Dim magentoConnection As New MagentoConnection(myConnString)
Dim magentoCommand As MagentoCommand = magentoConnection.CreateCommand()
magentoCommand.CommandText = "SELECT customer_id, firstname, lastname FROM Customers"
magentoConnection.Open()
Dim magentoReader As MagentoDataReader = magentoCommand.ExecuteReader()
Try
' Always call Read before accessing data.
While magentoReader.Read()
Console.WriteLine(String.Concat(magentoReader.GetInt32(0).ToString(), " ", _
magentoReader.GetString(1), " ", magentoReader.GetString(2)))
End While
Finally
' always call Close when done reading.
magentoReader.Close()
' Close the connection when done with it.
magentoConnection.Close()
End Try
End Sub |