Click here to Skip to main content
15,922,325 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I created a program which will send email notification to the user. Now, I want to count the record inside my reader.item("vendor_name") and display how many records was returned.

What I have tried:

Dim sqlcmd As New OleDb.OleDbCommand("SELECT aca.vendor_id, aca.vendor_name, pvs.phone,aca.CHECK_STOCK_ID, " & _
"pvs.email_address, aia.invoice_num, aip.amount, aip.accounting_date, " & _
"aip.invoice_id, aip.check_id, aia.Description FROM ap_checks_all aca, ap_invoice_payments_all aip, " & _
"ap_invoices_all aia, ap.ap_supplier_sites_all pvs, ap.AP_CHECK_STOCKS_ALL acs " & _
"Where aca.check_id = aip.check_id And pvs.vendor_site_id = aca.vendor_site_id " & _
"AND aip.invoice_id = aia.invoice_id AND aca.org_id = 86 AND aca.bank_account_name = 'BPI 0011117635' " & _
"AND aca.REMIT_TO_SUPPLIER_SITE = 'OFFICE' and acs.CHECK_STOCK_ID= aca.PAYMENT_DOCUMENT_ID(+) " & _
"AND UPPER (acs.name) = 'DEBIT ADVICE' AND aca.check_date = '" & Format(dtDate.Value, "yyyy-MMM-dd") & "' order by aca.vendor_id", cn)

Dim myreader As OleDb.OleDbDataReader
myreader = sqlcmd.ExecuteReader()

myreader.Read()
Dim rowCount As Integer = 0

If myreader.HasRows Then

rowCount += 1

irec = rowCount.ToString

txtmsg.Text = "Processing: " & myreader.Item("vendor_name").ToString & "'s Payroll..."
myreader.NextResult()

dtl = "Run Date: " & Now() & vbCrLf & _
                  "Mail Notification successful." & vbCrLf & _
                   irec & " records processed." & vbCrLf


MsgBox(dtl)
Posted
Updated 28-May-18 20:57pm

1 solution

Is there any reason why you don't just use
SQL
SELECT COUNT(*) FROM ...
as your SQL command? Then SQL will count them for you, and return the number of matching rows without wasting time transfering the records...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900