'Having issue with looping through all records
I need to loop through records of a specific database (currently there are only 3 records) and look at various cells within each row for specific dates. If the date is WITHIN 30 days a reminder is to come up noting something is coming due within 'x' days.
If the due date is PAST then a secondary reminder comes up to tell me the item is 'x' days past due.
I am getting the reminders of coming due or past due but it is only looking at the first record. It is not looping and reading the remaining records. Can someone assist me in advising where or how the for each loop is inserted in the below code please or even if for each is the proper loop syntax.?
Private Sub MedCertExpire()
Dim cmd As New SqlCommand
Dim reader As SqlDataReader
cmd.CommandType = CommandType.Text
cmd.Connection = New SqlConnection With {
.ConnectionString = My.MySettings.Default.PETS_DatabaseConnectionString
}
cmd.Connection.Open()
cmd.CommandText = "SELECT EMPLOYEE_FIRST_NAME
, DATEDIFF(DAY, GETDATE(), PHYSICAL_DATE) AS PHYSICAL_EXPIRES
, DATEDIFF(DAY, GETDATE(), CDL_EXPIRE_DATE) AS CDL_EXPIRES
, DATEDIFF(DAY, GETDATE(), TWIC_EXPIRES) AS TWIC_EXPIRES
, DATEDIFF(DAY, GETDATE(), PASSPORT_EXPIRES) AS PASSPORT_EXPIRES
, DATEDIFF(DAY, GETDATE(), ANNUAL_REVIEW_DATE) AS ANNUAL_REVIEW
FROM EMPLOYEE_TABLE"
Try
reader = cmd.ExecuteReader()
Dim yName As String
Dim yMedCert As Integer
Dim yCDL As Integer
Dim yTWIC As Integer
Dim yPass As Integer
Dim yRev As Integer
With reader
.Read()
yName = .GetString(0)
yMedCert = .GetInt32(1)
yCDL = .GetInt32(2)
yTWIC = .GetInt32(3)
yPass = .GetInt32(4)
yRev = .GetInt32(5)
Select Case yMedCert
Case Is <= 0
Call New MessageBoxMedCertExp(yName, yMedCert).ShowDialog()
Case Is <= 30
Call New MessageBoxMedCert(yName, yMedCert).ShowDialog()
End Select
Select Case yCDL
Case Is <= 0
Call New MessageBoxCDLExp(yName, yCDL).ShowDialog()
Case Is <= 30
Call New MessageBoxCDL(yName, yCDL).ShowDialog()
End Select
Select Case yTWIC
Case Is <= 0
Call New MessageBoxTWICExp(yName, yTWIC).ShowDialog()
Case Is <= 30
Call New MessageBoxTWIC(yName, yTWIC).ShowDialog()
End Select
Select Case yPass
Case Is <= 0
Call New MessageBoxPassExp(yName, yPass).ShowDialog()
Case Is <= 30
Call New MessageBoxPassport(yName, yPass).ShowDialog()
End Select
Select Case yRev
Case Is <= 0
Call New MessageBoxEmployeeReviewEXP(yName, yRev).ShowDialog()
Case Is <= 30
Call New MessageBoxEmployeeReview(yName, yRev).ShowDialog()
End Select
Return
End With
reader.Close()
Catch ex As Exception
MsgBox(ex)
End Try
cmd.Connection.Close()
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
