Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Guys, Here is the one problem very stupid problem am facing that is I want when data table is null so application will be closed and when data table is not null so it shows message box and return the form but when the data table is not null so form is closing I don't know what's the issue please check it and suggest me
Thanks

What I have tried:

if (dt44 ==null)
            {
                Application.Exit();
            }
            else
            {
                MessageBox.Show("Tables Are Open Login Again And punch Them", "Tables Open", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
Posted
Updated 9-Jul-17 3:15am

Using debugger, check that the data table dt44 is null. Chances are that is for example contains an empty data table or similar.

Another thing is that why not check the data table when the program starts, before you have created the form. This way you could decide whether to create the main form or not and you wouldn't have to worry about returning to the form. About main method, have a look at this conversation .c# - Where is the Main method in a forms application? - Stack Overflow[^]
 
Share this answer
 
You can use:
C#
if (dt44.Rows.Count <= 0)
 
Share this answer
 
Comments
Dave Kreskowiak 9-Jul-17 10:51am    
If dt44 is null, this call is going to fail with an exception.
RickZeeland 9-Jul-17 11:56am    
You are completely right, always test for null first !

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900