I know there are similar posts regarding this but i cant seem to find anything that works.
I'm still new to VB and this which is probably obvious is driving me mad.
What im looking to do is to Run a SQL SELECT and email the results to those who require it.
When i run it I'm getting the 'ELSE' email which states that there is nothing on HOLD, however running the Query in SQL Server Management Studio does present results.
Here is what i have:
Public Sub Main()
Dim connection As New SqlConnection(My.Settings.connectionString)
connection.Open()
Dim sqlCommand As SqlCommand
log(" Processing - Searching SQL Database for Held ONLN Jobs ")
Dim sqlQ1 As String = "Select [JobID] FROM [cemail].[dbo].[JobTb] " +
"WHERE ApplicationID = 7 AND Status = 10 ORDER BY [JobID]"
sqlCommand1 = New SqlCommand(sqlQ1, connection)
Dim result = sqlCommand1.ExecuteScalar()
Dim sqlQ2 As String = "Select [JobID],[JobNumber],[ApplicationID],[GeneratedDate]," +
"[ReceivedDate],[CompletedDate],[Status],[ExpectedRecordNumber]," +
"[ReceivedRecordNumber],[BadRecordNumber] " +
"FROM [cemail].[dbo].[JobTb] " +
"WHERE ApplicationID = 7 AND Status = 10"
sqlCommand2 = New SqlCommand(sqlQ2, connection)
Dim reader As SqlDataReader = sqlCommand2.ExecuteReader()
While reader.Read()
Dim jobID = reader(0)
Dim jobNumber = reader(1)
Dim appID = reader(2)
End While
If (result > 0) Then
SendEmail(My.Settings.emailuser1, "Current Held Jobs", "Hello," & jobID & "Kind Ragards" )
Else
SendEmail(My.Settings.emailuser1, "No Jobs on Hold", "There are no Jobs Currently on Hold" )
End If
connection.Close()
log("Finished")
End Sub
Any help on this would be greatly appreciated. thanks in Advance.