473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Check the empty table

JustRun
127 100+
Hi,
I just want to know what is the number that will return if the table is empty "has no record"
Is it ' 0 ' ?
Jun 1 '09 #1
18 2318
tlhintoq
3,525 Expert 2GB
"the number"? I'm sure there a many numbers associated with a table. Which one do you mean? Record count would be zero.

TIP: Feel safe to experiment more. What harm can you do? Build two are three small tables. Put no records in one of them. Put 10 records in one of them. Generate 100,000 records for one of them. Use these for your testing. It can be enlightening to see how routines that seem to work fine on 10 records are less than expected at 100,000.
Jun 1 '09 #2
artov
40
There are two cases where zero comes on "empty table":

1. If table's size is zero:

Expand|Select|Wrap|Line Numbers
  1. Type table[] = new Type[0];
then Length property (table.Length) of the table is zero.

2. When table is created, its elements contain default value of the Type. If the Type is numeric value, its default value is zero (either integer zero, floating zero or decimal zero). In a way, this kind of table is empty, since there is no application data inserted yet.
Jun 2 '09 #3
JustRun
127 100+
Well here is my Case

Expand|Select|Wrap|Line Numbers
  1. public int tableRecords;
  2.  
  3. //public int tableRecords
  4.         //{
  5.         //    get { return _tableRecords; }
  6.         //    set { _tableRecords = value; }
  7.         //}
  8.  
  9. public int CountTableRecords(string _userName, string _projectName)
  10.         {
  11.             try
  12.             {
  13.                 cmd = new SqlCommand("SELECT COUNT(ActivationKey) AS ActKey FROM ActivationTable "+
  14.                     " WHERE (UserName = @UserName) AND (ProjectName = @ProjectName)", con);
  15.  
  16.                 cmd.Parameters.AddWithValue("UserName", _userName);
  17.                 cmd.Parameters.AddWithValue("ProjectName", _projectName);
  18.  
  19.                 tableRecords = (Int32)cmd.ExecuteScalar();
  20.             }
  21.             catch (Exception ex)
  22.             {
  23.                 msg.err = ex.Message.ToString();
  24.             }
  25.             return tableRecords;
  26.         }
  27.  
Inside the SQL view thi query returns the correct number ( 0=no records , number = records number )
The problem is in my C# code, it always returns 0 ,

Any one can correct my code and tell me why .

Thanks
Jun 2 '09 #4
r035198x
13,262 8TB
Shouldn't
Expand|Select|Wrap|Line Numbers
  1. cmd.Parameters.AddWithValue("UserName", _userName);
be
Expand|Select|Wrap|Line Numbers
  1. cmd.Parameters.AddWithValue("@UserName", _userName);
instead?
Jun 2 '09 #5
JustRun
127 100+
I don't think so, I always do my queries in that format and it always works, Also I replaced the variables (@UserName, ....) with constant values Still return ZERO :(((((
Jun 2 '09 #6
r035198x
13,262 8TB
@JustRun
That's not what MSDN says. See their examples.
@JustRun
Then either the query does return 0 records or you are getting an exception.
Jun 2 '09 #7
JustRun
127 100+
Well, I fount the problem , the query is correct, the problem in the connection,

As fro the MSDN, they might say so cause this is the recommended format or the standard but it works without the @ sign :)

Really thanks for your reply.
Jun 2 '09 #8
r035198x
13,262 8TB
So you were getting an Exception?
Jun 2 '09 #9
JustRun
127 100+
OH GOD
I thought that I have a problem within the Connection when I tried to test the result directly from a Form, not get it in a business Class then call it in the form

well now I think I should place my code here, it will be long but I'll try to clarify :(
Jun 2 '09 #10
r035198x
13,262 8TB
Better separate all that database access code from your interface code. It makes it easier to debug your code and makes your code reusable.
You should also never connect to databases on the same thread that draws the interface.
Jun 2 '09 #11
JustRun
127 100+
I do that already, but guess what , The same method that counts the table records return the correct number from the interface Form bur return Zero from the business class

I checked the connection , it works with no problem.

I'm Stuck
Jun 2 '09 #12
r035198x
13,262 8TB
Then the method is dependent on something being provided in the form but being provided in the business class.
P.S. Business classes should also not contain any SQL. See the DAO pattern for one way of separating these concerns.
Jun 2 '09 #13
JustRun
127 100+
well, I'm checking my bussiness class again now, and i'll tell you the result
wish me luck :(
Jun 2 '09 #14
JustRun
127 100+
by the way there is no SQL in my bussiness class, but it might there a conflict with (if else) they are much, i'll try to find a way to separate them and organize the code in a better way
Jun 2 '09 #15
JustRun
127 100+
Yesssssssssssssssss,
Jun 2 '09 #16
JustRun
127 100+
IT WORKESSSSSSSSSSS, i just rotate some IF statements with others and it workkssss :D

Thanks for your patient and Quick following
Now I can Take my break ;)
Jun 2 '09 #17
r035198x
13,262 8TB
Yeah I'll go and make myself a cup of Rooibos too.
Jun 2 '09 #18
JustRun
127 100+
hhhhhhhhhhh, yeah ;D
Jun 2 '09 #19

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

Similar topics

3
by: KathyB | last post by:
Hi, I'm trying to find a way to validate input text boxes where I don't know the names until the page is rendered. I've got 2 validate functions that fire with the onsubmit button of a "mini" form...
7
by: Tony Johnson | last post by:
Can you make a check box very big? It seems like when you drag it bigger the little check is still the same size. Thank you, *** Sent via Developersdex http://www.developersdex.com ***...
7
by: G G | last post by:
I need to check if a table exists in Access using ADO externally. I tried "Select Name from MSysObjects Where Name = 'myTable'" with the ADO command object, but I got an error than I don't...
2
by: Chris Windsor | last post by:
I hope the following describe what I'm trying to do: I have created a tool to be used by product analysts when studying different cell phone designs. Part of the tool is a set of 11 forms on a...
5
by: Krechting | last post by:
Hi ALl, I have a code that checks if the documents in a hyperlink field are still where they should be. I use fileexist(). First I want to filter out all the hyperlink fields that are empty. I...
16
by: Brian Tkatch | last post by:
Is there a way to check the order in which SET INTEGRITY needs to be applied? This would be for a script with a dynamic list of TABLEs. B.
4
by: andrewbda | last post by:
How do I check if a table is empty in access? I need to run different VB depending on if a certain table is empty or not. Thanks!
1
by: newbieBrian | last post by:
I have a program that combines the contents of other tables into one tables. If it sees any bad data from each table, it stores it into the tables called errors: So the inputs like this:...
12
by: maheswaran | last post by:
Hi Guys, I want to check if a table is empty or not? In my table (i.e test) have no records and id is a primary key as well as auto increment column. i have using to find this "select...
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.