I'm trying to retrieve data from a LiteDB NOSQL database but i'm struggling to get the syntax correct in Visual Basic.
The database is created correct (validated in LiteDBViewer) and I can count the values in the collection, but when I try to generate the query using collection.Find()
, Intellisense puts in query:=
, not Query.Operation
, as per the documentation.
Try
Using db As LiteDB.LiteDatabase = New LiteDB.LiteDatabase("Sig.db")
Dim brands = db.GetCollection(Of Brand)("Brand")
Dim brands_count As Integer = brands.Count()
If brands_count > 0 Then
'get Brands
Dim brands_results = brands.Find(query:=("Name")) <-- Problem Row
Dim brand_name As String
For Each result In brands_results
brand_name = result.Name.ToString
BrandGrid.Rows.Add(New String() {brand_name, True, True})
Next
End If
End Using
Catch SQLex As LiteDB.LiteException
MessageBox.Show(SQLex.Message, SQLex.ErrorCode.ToString, MessageBoxButtons.OK, MessageBoxIcon.Error)
Catch ex As Exception
MessageBox.Show(ex.Message, ex.InnerException.ToString, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
I guess I'm struggling with the converting the c# code to VB.net or missing something obvious.
All help or advice appreciated.
Speaking to the developer over Twitter, he suggested using Lambda Expressions.
As a result, the value is as follows:
Dim brands_results = brands.Find(Function(x) x.Name.Equals(SelectedBrand))
(SelectedBrand
being a string variable declared earlier)