Reads a forward-only stream of rows from Google BigQuery.
The following example creates a
BigQueryConnection, a
BigQueryCommand, and a
BigQueryDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the
BigQueryDataReader, then the
BigQueryConnection.
|
|---|
public void ReadMyData(string myConnString) {
BigQueryConnection bigQueryConnection = new BigQueryConnection(myConnString);
BigQueryCommand bigQueryCommand = (BigQueryCommand)bigQueryConnection.CreateCommand();
bigQueryCommand.CommandText = "SELECT id, first_name, last_name FROM your_project.your_dataset.employees";
bigQueryConnection.Open();
BigQueryDataReader bigQueryReader = bigQueryCommand.ExecuteReader();
try {
// Always call Read before accessing data.
while (bigQueryReader.Read()) {
Console.WriteLine(bigQueryReader.GetInt64(0) + " " +
bigQueryReader.GetString(1) + " " + bigQueryReader.GetString(2));
}
}
finally {
// always call Close when done reading.
bigQueryReader.Close();
// Close the connection when done with it.
bigQueryConnection.Close();
}
} |
|
|---|
Public Sub ReadMyData(ByVal myConnString As String)
Dim bigQueryConnection As New BigQueryConnection(myConnString)
Dim bigQueryCommand As BigQueryCommand = bigQueryConnection.CreateCommand()
bigQueryCommand.CommandText = "SELECT id, first_name, last_name FROM your_project.your_dataset.employees"
bigQueryConnection.Open()
Dim bigQueryReader As BigQueryDataReader = bigQueryCommand.ExecuteReader()
Try
' Always call Read before accessing data.
While bigQueryReader.Read()
Console.WriteLine(String.Concat(bigQueryReader.GetInt64(0), " ", _
bigQueryReader.GetString(1), " ", bigQueryReader.GetString(2)))
End While
Finally
' always call Close when done reading.
bigQueryReader.Close()
' Close the connection when done with it.
bigQueryConnection.Close()
End Try
End Sub |