VB.NET MySQL - datatable returns blank row while db has no data -


i trying search data in mysql table...

dim cmd new mysqlcommand dim qry string = "select sum(amt) fee_payment roll_no='" + st_roll + "' , course='" + c_id + "'" cmd.connection = conn cmd.commandtext = qry  dim dt new datatable dim dadapter new mysqldataadapter dadapter.selectcommand = cmd dadapter.fill(dt) if dt.rows.count > 0     dim dr mysqldatareader = cmd.executereader     while dr.read         dim t_paid = dr("sum(amt)")         tbdue.text = tot_fees - t_paid     end while     dr.close() end if 

surprisingly above dt.rows.count returns 1 while table fee_payment has no data.

what should ??

there nothing surprising @ result.

an aggregation query no group by always returns 1 row. if rows filtered out, aggregation functions return null, although count() , count(distinct) return 0.

this standard behavior , how databases work. quite convenience under circumstances.

edit:

if wanted behavior no rows returned, add group by:

select sum(amt) fee_payment roll_no = '" + st_roll + "' , course = '" + c_id + "' group roll_no, course; 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -