Represents an open connection to Google BigQuery.
The following example creates a
BigQueryCommand and a
BigQueryConnection. The
BigQueryConnection is opened and set as the
Connection property. The example then calls
ExecuteNonQuery method, and closes the connection. To accomplish this, the
ExecuteNonQuery is passed a connection string and a query string that is SQL INSERT statement.
|
|---|
public void InsertRow(string bigQueryConnectionString)
{
// If the connection string is empty, use default.
if(bigQueryConnectionString == "")
{
bigQueryConnectionString =
@"Authentication Type=ServiceAccount;ServiceAccount Json=C:\keys\service-account.json;Project Id=your_project;DataSet Id=your_dataset;License Key=**********";
}
BigQueryConnection myConn = new BigQueryConnection(bigQueryConnectionString);
string myInsertQuery = "INSERT INTO your_project.your_dataset.employees (first_name, last_name) VALUES ('John', 'Smith')";
BigQueryCommand bigQueryCommand = new BigQueryCommand(myInsertQuery);
bigQueryCommand.Connection = myConn;
myConn.Open();
try
{
bigQueryCommand.ExecuteNonQuery();
}
finally
{
myConn.Close();
}
} |
|
|---|
Public Sub InsertRow(bigQueryConnectionString As String)
' If the connection string is empty, use default.
If bigQueryConnectionString = "" Then
bigQueryConnectionString = _
"Authentication Type=ServiceAccount;ServiceAccount Json=C:\keys\service-account.json;Project Id=your_project;DataSet Id=your_dataset;License Key=**********"
End If
Dim myConn As New BigQueryConnection(bigQueryConnectionString)
Dim myInsertQuery As String = "INSERT INTO your_project.your_dataset.employees (first_name, last_name) VALUES ('John', 'Smith')"
Dim bigQueryCommand As New BigQueryCommand(myInsertQuery)
bigQueryCommand.Connection = myConn
myConn.Open()
Try
bigQueryCommand.ExecuteNonQuery()
Finally
myConn.Close()
End Try
End Sub |