I am trying to figure out how to display certain data from an access database based on the button click. For example, if I clicked the Stock button then it would display the items from the database where the item is out of stock. I am able to open the connection and display query information but it is a long LINQ query that I am not sure where it came from. Any suggestions on how to display the database information? i.e. customer information, stock items, etc…
Option Strict On
Imports System.Data.OleDb
Public Class frmMicroland
Dim con As New OleDbConnection
Private Sub btnStockItems_Click(sender As System.Object, e As System.EventArgs) Handles btnStockItems.Click
Dim query1 = From anyOrder In MICROLANDDataSet.Orders
Join itsStockItem In MICROLANDDataSet.Inventory
On anyOrder.itemID Equals itsStockItem.itemID
Let orderQuantity = anyOrder.quantity
Select itsStockItem.quantity, itsStockItem.description, anyOrder.itemID
Order By quantity, itemID
''Test connection to make sure it opens first
Try
con = New OleDb.OleDbConnection("provider= microsoft.ace.oledb.12.0;Data Source = C:\Users\HPG62-220US\Documents\Visual Studio 2010\Projects\Asignment 9\Asignment 9\bin\Debug\MICROLAND.accdb; Persist Security Info=False;")
Try
Call con.Open()
Catch ex As Exception
MessageBox.Show("Could not connect")
End Try
If con.State = ConnectionState.Open Then
MessageBox.Show("Connection is open")
End If
Catch ex As Exception
End Try
lstOutput.Items.Add("Here are the items that are out of")
lstOutput.Items.Add("inventory or must be reordered.")
lstOutput.Items.Add("")
lstOutput.Items.Add("The numbers shown give the")
lstOutput.Items.Add("minimum reorder quantity required.")
lstOutput.Items.Add("")
lstOutput.Items.Add(query1)
con.Close()
End Sub
Private Sub btnTodaysOrders_Click(sender As System.Object, e As System.EventArgs) Handles btnTodaysOrders.Click
End Sub
End Class
There are a few different things going on here…
Firstly, you need to declare a variable outside of your btnStockItems_Click procedure that can store the returned dataset. sometihng like:
Then in your btnStockItems_Click procedure you need to populate that datatable:
Now you have the data to use in each of the button clicks.
The next problem I see is that it doesn’t seem you pulled in the correct data…
For example, you never pulled in the order date in your query1, but you’re looking to know today’s orders.
Assuming you fixed that and it was called, say “OrderDate” in query1, what you could do then is populate your listview with a linq query from your ReturnedData datatable something along the lines of:
… I’m doing this without an IDE, so spelling may be off, but I hope this gives you an idea of where to go…