By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,805 Members | 1,100 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,805 IT Pros & Developers. It's quick & easy.

query returns Dataset table rows count 1 with no data in the table

P: 3
Hi,

I am using a query "Select SUM(Amount) from tblAccount where TransactionID=' "+textBox1.Text+" ' "; in my C# project this query return

dataset.Tables[0].Rows.Count =1 eventhough there is no data in my table Account ie, No data row in that table i am expecting a count=0, but i am not getting the correct result Database is MS Access and i am using Visual studio 2005 . DB connector used is OLEDB connector pl help me
Nov 16 '08 #1
Share this Question
Share on Google+
7 Replies


vanc
Expert 100+
P: 211
Try to set AllowUserToAddRow property to False and try again.
Nov 17 '08 #2

balabaster
Expert 100+
P: 797
Er - your query will always return 1 row - regardless of if there's any data in your table or not...

Question: What's the sum of 0 rows?

Well - given that there's no rows to sum, the value will be 0....or if there's 100 rows, it could be whatever, but the sum of a set of items will always produce a value, whether it's a zero value or not...

It's the same as if I give you a bag and ask you how many items are in it - you open the bag and there's no items... you don't tell me null/void/nothing. You tell me there's 0 items in the bag.
Nov 17 '08 #3

P: 3
Try to set AllowUserToAddRow property to False and try again.
Could you explain in detail? i think Allow User to Add Row property is associated with Datagrid. Here i am using this query to bind a textbox
Nov 18 '08 #4

P: 3
Er - your query will always return 1 row - regardless of if there's any data in your table or not...

Question: What's the sum of 0 rows?

Well - given that there's no rows to sum, the value will be 0....or if there's 100 rows, it could be whatever, but the sum of a set of items will always produce a value, whether it's a zero value or not...

It's the same as if I give you a bag and ask you how many items are in it - you open the bag and there's no items... you don't tell me null/void/nothing. You tell me there's 0 items in the bag.

I too agree with you. But When i used dataset.Tables[0].Rows[0][0] it should return 0, but i am getting There is now row in 0 position. How can i get rid of this problem any other solution please
Nov 18 '08 #5

Plater
Expert 5K+
P: 7,872
When I run a similar query where it SUMs no rows, I get a Null value returned (not a 0 )
Nov 18 '08 #6

balabaster
Expert 100+
P: 797
When I run a similar query where it SUMs no rows, I get a Null value returned (not a 0 )
You might get a null value, but you still get a row returned...that contains that null value...
Nov 18 '08 #7

P: 1
Try ExecuteScalar function
Feb 5 '12 #8

Post your reply

Sign in to post your reply or Sign up for a free account.