我知道有关于此的类似帖子,但我似乎找不到任何有用的东西。
我还是 VB 的新手,这可能很明显让我发疯。
我想做的是运行 SQL SELECT 并将结果通过电子邮件发送给需要它的人。
当我运行它时,我收到一封“ELSE”电子邮件,其中指出没有任何内容处于 HOLD 状态,但是在 SQL Server Management Studio 中运行查询确实会显示结果。
这是我所拥有的:
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
对此的任何帮助将不胜感激。提前致谢。