by Gehan Fernando (47 Submissions)
Category: Databases/Data Access/DAO/ADO
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Thu 21st December 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)
VB.Net - Easy Stock Monitor Code "Try It"....
API Declarations
Imports System.Data
Imports System.Data.OleDb
REM List View Settings"
'ListView Name :- LstStock
'GridLines :- True
'View :- Details
Try
Me.Cursor = Cursors.WaitCursor
Dim CurrentRow As Integer = 0
Const PRODUCTID_COLUMN As Integer = 0
Const PRODUCT_COLUMN As Integer = 1
Const UNITS_INSTOCK_COLUMN As Integer = 2
Const UNITS_ONORDER_COLUMN As Integer = 3
Const REORDERLEVEL_COLUMN As Integer = 4
Const DISCONTINUED_COLUMN As Integer = 5
Dim OleCon As New System.Data.OleDb.OleDbConnection()
OleCon.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=E:\Program Files\Microsoft Visual Studio\VB98\NWIND.MDB"
Dim SqlStr As String = "SELECT ProductID,ProductName,UnitsInStock," & _
"UnitsOnOrder,ReorderLevel,Discontinued FROM Products"
Dim OleCom As New System.Data.OleDb.OleDbCommand(SqlStr, OleCon)
OleCom.Connection.Open()
Dim OleReader As System.Data.OleDb.OleDbDataReader = OleCom.ExecuteReader()
LstStock.Items.Clear()
While OleReader.Read() = True
LstStock.Items.Add(OleReader.Item("ProductID"))
LstStock.Items.Item(CurrentRow).SubItems.Add(OleReader.Item("ProductName"))
LstStock.Items.Item(CurrentRow).SubItems.Add(OleReader.Item("UnitsInStock"))
LstStock.Items.Item(CurrentRow).SubItems.Add(OleReader.Item("UnitsOnOrder"))
LstStock.Items.Item(CurrentRow).SubItems.Add(OleReader.Item("ReorderLevel"))
LstStock.Items.Item(CurrentRow).SubItems.Add(OleReader.Item("Discontinued"))
If OleReader.GetInt16(UNITS_INSTOCK_COLUMN) <= _
OleReader.GetInt16(REORDERLEVEL_COLUMN) And _
OleReader.GetInt16(UNITS_ONORDER_COLUMN) = 0 And _
OleReader.GetBoolean(DISCONTINUED_COLUMN) = False Then
LstStock.Items.Item(CurrentRow).SubItems.Item( _
PRODUCTID_COLUMN).ForeColor = Drawing.Color.White
LstStock.Items.Item(CurrentRow).SubItems.Item( _
PRODUCTID_COLUMN).BackColor = Drawing.Color.DarkRed
End If
If OleReader.GetInt16(UNITS_INSTOCK_COLUMN) <= _
OleReader.GetInt16(REORDERLEVEL_COLUMN) And _
OleReader.GetInt16(UNITS_ONORDER_COLUMN) = 0 And _
OleReader.GetBoolean(DISCONTINUED_COLUMN) = True Then
LstStock.Items.Item(CurrentRow).SubItems.Item( _
PRODUCTID_COLUMN).ForeColor = Drawing.Color.White
LstStock.Items.Item(CurrentRow).SubItems.Item( _
PRODUCTID_COLUMN).BackColor = Drawing.Color.DarkOliveGreen
End If
CurrentRow = CurrentRow + 1
End While
Me.Cursor = Cursors.Default
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Cursor = Cursors.Default
End Try
End Sub