This is a first example of application in vb.net that write and read datas using Cassandra and HectorSharp interface(http://hectorsharp.com/). Just download HectorSharp and compile it to create libraries for your project. Obviously, we need to create a referenco to the HectorSharp library in our project before we can use it.
In this example we use the default keyspace of Cassandra (Keyspace1) and also a default Cassandta column family (Standard1).
We'll create a column called "MyColumn" in the column family and we'll put in a value.
For this purpose, we'll use a Web Application with label, called “lbltest”, where we'll show data picked from Cassandra.
Imports HectorSharp
[…]
'db connection
Dim cf As New KeyedCassandraClientFactory(New CassandraClientPoolFactory().Create(), _
New KeyedCassandraClientFactory.Config())
Dim client = cf.Make(New Endpoint("localhost", 9160))
'db definition (keyspace)
Dim keyspace = client.GetKeyspace("Keyspace1")
'Dim path = New ColumnPath(columnfamily name, supercolumn name (if present), column name)
Dim path = New ColumnPath("Standard1", "", "MyColumn")
'insert a value in db
keyspace.Insert("0", path, "My new value")
'get the value
Dim column As Column = keyspace.GetColumn("0", path)
lbltest.Text = column.Value
Dim client = cf.Make(New Endpoint("localhost", 9160))
'db definition (keyspace)
Dim keyspace = client.GetKeyspace("Keyspace1")
'Dim path = New ColumnPath(columnfamily name, supercolumn name (if present), column name)
Dim path = New ColumnPath("Standard1", "", "MyColumn")
'insert a value in db
keyspace.Insert("0", path, "My new value")
'get the value
Dim column As Column = keyspace.GetColumn("0", path)
lbltest.Text = column.Value
How you can see, working with Cassandra using HectorSharp is really simple.