如何统计读者的记录 [英] How to count record in reader
本文介绍了如何统计读者的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了一个程序,它会向用户发送电子邮件通知。现在,我想计算我的reader.item(vendor_name)中的记录,并显示返回的记录数。
我尝试过:
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)
推荐答案
正如我对你或你的同学说的那样:
As I said to you or your class mate:
引用:
你有没有理由不使用
Is there any reason why you don't just use
SELECT COUNT(*) FROM ...
作为您的SQL命令?然后SQL将为您计算它们,并返回匹配的行数而不浪费时间传输记录...
as your SQL command? Then SQL will count them for you, and return the number of matching rows without wasting time transfering the records...
你可以使用while
循环遍历直到myreader.Read()
返回值并在循环内生成一个count变量。
You can use awhile
loop to traverse tillmyreader.Read()
return value and incriment a count variable inside the loop.
While reader.Read()
rowCount += 1
End While
它会给您的记录数
it will give you number of records
这篇关于如何统计读者的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文