Database Reference
In-Depth Information
Writing Data
Once our schema has been created, we can load in some data. In this example, we
will add a couple of rows to our table. Listing 9.12 shows example insert state-
ments.
Listing 9.12 Writing Data in C#
Click here to view code image
public void LoadData() {
session.Execute("INSERT INTO portfo-
lio_demo.portfolio " +
"(portfolio_id, ticker, current_price, " +
" current_change, current_change_percent)
VALUES " +
"(756716f7-2e54-4715-9f00-91dcbea6cf50,
'GOOG', " +
" 889.07, -4.00, -0.45);");
session.Execute("INSERT INTO portfo-
lio_demo.portfolio " +
"(portfolio_id, ticker, current_price, " +
" current_change, current_change_percent)
VALUES " +
"(756716f7-2e54-4715-9f00-91dcbea6cf50,
'AMZN', " +
" 297.92, -0.94, -0.31);");
}
Reading Data
When reading data, the query execution will return an instance of ResultSet
that will allow access to the values of the fields requested. Listing 9.13 shows
query execution and printing the results to the console.
Listing 9.13 Reading Data in C#
Click here to view code image
 
 
Search WWH ::




Custom Search