Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9166157
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:05:34+00:00 2026-06-17T15:05:34+00:00

I know there are similar posts regarding this but i cant seem to find

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:05:35+00:00Added an answer on June 17, 2026 at 3:05 pm

    You should not call on ExecuteNonQuery when you pass a Select statement.
    As from the remarks on MSDN

    For UPDATE, INSERT, and DELETE statements, the return value is the
    number of rows affected by the command. ……… For all other types of
    statements, the return value is -1…….

    You could change the statement to simplify your query in this way

    Dim sqlQ As String = "Select count(*) as recFound FROM [cemail].[dbo].[JobTb] " + 
                         "WHERE ApplicationID = 7 AND Status = 10"
    
    sqlCommand = New SqlCommand(sqlQ, connection)
    Dim result = sqlCommand.ExecuteScalar()
    

    Also, in the code above there is no need to use a transaction.

    EDIT Seeing your comment I will show also the part for reading back the values from the database using an SqlDataReader

    Dim sqlQ As String = "Select [JobID],[JobNumber],[ApplicationID],[GeneratedDate]," +
                        "[ReceivedDate],[CompletedDate],[Status],[ExpectedRecordNumber]," + 
                        "[ReceivedRecordNumber],[BadRecordNumber] " + 
                        "FROM [cemail].[dbo].[JobTb] " + 
                        "WHERE ApplicationID = 7 AND Status = 10"
    
    sqlCommand = New SqlCommand(sqlQ, connection)
    Dim reader As SqlDataReader = sqlCommand.ExecuteReader()
    While reader.Read()
         Dim jobID = reader(0)
         Dim jobNumber = reader(1)
         Dim appID = reader(2)
         ..... 'and so on'
    End While 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there a lot of similar questions to this, but I didn't find
I know there are lots of posts similar to this, but after crawling SO,
I know there are other posts similar to this one, but none of them
I know there are other posts similar to this, but everyone recommends just doing
I know there are a few similar posts about this topic, but none were
I've got troubles with .htaccess, I know there are similar posts, but I cant
I know there are questions similar to this one, but I've not found a
I know there have been some similar questions to this, but they haven't helped
I can't seem to find any similar topics online regarding this, so apologies for
I know there are similar, more complex posts around, but I just can't get

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.