Selecting/Filtering Data from LiteDB in Visual Basic .NET - vb.net

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)

Related

upload files to dropbox using dropbox api

i'm working in a console app that is going to be executed in a server every week, basically it generates a report in excel and then it has to upload it to a folder in dropbox, i've trying a lot of stuff for that last part i finally got this code that does not work but doesn't throw any exception (before i had one that throw and invalid folder format)
Dim _path As String
_path = "/Pruebas/" & Path.GetFileName(FilePath)
Try
Dim rawData = File.ReadAllBytes(FilePath)
Dim str = System.Text.Encoding.Default.GetString(rawData)
Using mem = New MemoryStream(Encoding.UTF8.GetBytes(str))
Dim Up = I.Files.UploadAsync(_path, body:=mem)
MsgBox("Successfully Uploaded")
End Using
Catch ex As Exception
MsgBox(ex.Message)
End Try
it doesn't throw exception but also doens't work, any help i'll be thankfull.
try this.
Dim Up = I.Files.UploadAsync(_path, WriteMode.Overwrite.Instance, body:=mem)
Link to documentation: http://dropbox.github.io/dropbox-sdk-dotnet/html/M_Dropbox_Api_Files_Routes_FilesUserRoutes_UploadAsync_1.htm

How to update an MS Access database using a dataset in visual basic?

Hi I am currently working on a project on visual Basic 2010, what i am stuck on now is updating my MS Access database triggered by a button click.
I already have the connection and data adapter established and i generated a data set for the data adapter, and i have used the data set. what i am trying to do is read from a data grid view entries the user have typed in and save these changes to the data set, and finally save the dataset back into the database using the oledbdataadapter.update(dataset) command. I tried everything and i have been stuck for a while, there are no errors in the code and I can see the changes made to the dataset are successful and i can view them (i am getting the "update successful" at the end of the try so i am sure the code is executing till then and not going to exception), but i simply don't see the changes in the database.
below is the code, i will appreciate any help you can offer thank you.
For j As Integer = 6 To DataGridView1.Rows.Count
Try
Dim s As String = DataGridView1.Rows(j).Cells(0).Value
Dim Quantaties As Integer = DataGridView1.Rows(j).Cells(3).Value
For i As Integer = 0 To DataSet21.Tables("Stock").Rows.Count
Dim foundRow As DataRow = DataSet21.Tables("Stock").Rows.Find(i)
If foundRow IsNot Nothing Then
If foundRow(1) = s Then
DataSet21.Tables("Stock").Rows(i).Item(7) = Quantaties
DataSet21.AcceptChanges()
Try
Dim builder As New OleDbCommandBuilder(OleDbDataAdapter1)
Me.Validate()
OleDbDataAdapter1.UpdateCommand = builder.GetUpdateCommand()
OleDbDataAdapter1.Update(DataSet21.Stock)
DataSet21.AcceptChanges()
MsgBox("Update successful")
Catch ex As Exception
MsgBox("Update failed")
End Try
End If
End If
Next
BindingSource1.EndEdit()
Catch ex As Exception
End Try
Next
thank you for your reply.
I guess both ways work OleDbDataAdapter1.Update(DataSet21.Stock) and OleDbDataAdapter1.Update("DataSet21"), because i figured out what was wrong with my code. the problem was in the DataSet21.AcceptChanges() i should not have placed it before the OleDbDataAdapter1.Update(DataSet21.Stock).
the OleDbDataAdapter.update() saves changes done in the dataset to the database and the dataset.acceptchanges() makes the dataset save the changes done to it making it seem that it doesn't have changes in it anymore. so the OleDbDataAdapter.update() was not executing since the dataset didn't have changes done to it because of the dataset.acceptchanges()
so what i did was remove dataset.acceptchanges() and it finally worked. my code looks like this now.
For j As Integer = 6 To DataGridView1.Rows.Count
Try
Dim s As String = DataGridView1.Rows(j).Cells(0).Value
Dim Quantaties As Integer = DataGridView1.Rows(j).Cells(3).Value
For i As Integer = 0 To DataSet21.Tables("Stock").Rows.Count
Dim foundRow As DataRow = DataSet21.Tables("Stock").Rows.Find(i)
If foundRow IsNot Nothing Then
If foundRow(1) = s Then
DataSet21.Tables("Stock").Rows(foundRow(0) - 2).Item(7) = Quantaties
Try
BindingSource1.EndEdit()
OleDbDataAdapter1.Update(DataSet21.Stock)
MsgBox("Update successful")
Catch ex As Exception
MsgBox("Update failed")
End Try
End If
End If
Next
Catch ex As Exception
End Try
Next

Stop using a file

first i created a file by pressing on a label then i want to be able to delete it without restarting app (because it becomes in use)
code is
Dim UniWinDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "UniWin Activator Data")
Dim MsgIODat = Path.Combine(UniWinDataPath, "MessageIO.dat")
If File.Exists(MsgIODat) Then
'ERROR HERE
File.Delete(MsgIODat)
'''''''''''''''''''''
Dim clrdata = MessageBox.Show("Data Cleared.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
ElseIf (Not (File.Exists(MsgIODat))) Then
Dim nodata = MessageBox.Show("There is no data to clear.", "", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
error: The process cannot access the file '(PATH)' because it is being used by another process.
i've searched and didn't find anyone talking about this in vb.net language
is there a way to let my app stop using it to delete the file?
You need to dispose the FileStream returned by the File.Create() Method.
When you create the file,
File.Create("file").Dispose()

VB.net TableAdapter.Update not updating database

I'm adding a new row to an Access 2010 database, and attempting to update the new row using TableAdapter.Update(). The code does not throw an exception, and it does not make a successful update to the database either. I've checked the original DB for changes, the one in the project folder, and the copy that is made in bin and there are no changes to any of them. Here is my code and any feedback would be greatly appreciated.
Private Sub insertRow(job As String, part As String, castDate As Date, inspectDate As Date, NCIR As Integer)
Dim row As As_Cast_DBDataSet.As_CastRow
Dim adapter As New As_Cast_DBDataSetTableAdapters.As_CastTableAdapter
row = Me.DBDataSet.As_Cast.NewAs_CastRow()
adapter = Me.As_CastTableAdapter
row.Job_Number = job
row.Part_Number = part
row.Casting_Date = castDate
row.Inspection_Date = inspectDate
row.NCIR = NCIR
Try
Me.DBDataSet.As_Cast.Rows.Add(row)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
Try
adapter.Update(Me.DBDataSet.As_Cast)
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub

Getting Control Properties by Function VB.NET

I am trying to create a function that will create some properties for a control (in this case, a combobox). However, the receiving control does not get the value properties from the function.
Here is the function that creates the property.
Public Function getComboboxProperties(ByVal dt As DataTable) As
ComboBox
Try
Dim ctrlCombobox As New ComboBox
ctrlCombobox.BindingContext = New BindingContext
ctrlCombobox.DataSource = dt
ctrlCombobox.ValueMember = "ID"
ctrlCombobox.DisplayMember = "DESCRIPTION"
getComboboxProperties = ctrlCombobox
Catch ex As Exception
Return Nothing
MessageBox.Show(ex.ToString, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try End Function
new value is passed by:
cmbCompanyStatus = clsCommon.getComboboxProperties(dtStatus)
When I open the form, combobox cmbCompanyStatus does not pick up the datasource and displays nothing.
Any help would be greatly appreciated. Thank you!.
Looking at this, you appear to be missing the following:
' Snip
ctrlCombobox.DataSource = dt
ctrlCombobox.ValueMember = "ID"
ctrlCombobox.DisplayMember = "DESCRIPTION"
ctrlCombobox.DataBind() ' <-------------------- This line here
getComboboxProperties = ctrlCombobox
I would suggest the likely cause is an exception being thrown somewhere in your assignments. The statements
Return Nothing
MessageBox.Show(ex.ToString, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
are the wrong way round; the function will return without displaying the message box.
Also,
getComboboxProperties = ctrlCombobox
is a rather old-fashioned way of returning a value; in VB.Net one would prefer
Return ctrlCombobox