469,327 Members | 1,212 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,327 developers. It's quick & easy.

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

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
7 8017
vanc
211 Expert 100+
Try to set AllowUserToAddRow property to False and try again.
Nov 17 '08 #2
balabaster
797 Expert 512MB
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
kunku
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
kunku
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
7,872 Expert 4TB
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
797 Expert 512MB
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
Try ExecuteScalar function
Feb 5 '12 #8

Post your reply

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

Similar topics

4 posts views Thread by Orion | last post: by
3 posts views Thread by Andrew Mueller | last post: by
5 posts views Thread by Roy Lawson | last post: by
2 posts views Thread by =?Utf-8?B?Q2hyaXM=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by Purva khokhar | last post: by
reply views Thread by haryvincent176 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.