Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to use a progress bar to indicate that the windows form is accessing the database and processing the enquire, but i dont know how to set the maximum, since i don't know how long the database is going to take to perform the enquire, can anyone shed some light here ,thanks.

Cheers
Posted

1 solution

No. We can't. We don't know either.

How long is a piece of string?

How much data are you fetching? How fast is your server? What is the connection like? Are you returning the result of a simple query or a complex stored procedure? What is your server load like at the moment of the query? These and other factors will affect the time taken.

You can force SQL server to give you a progress indication, but it isn't simple, and may be more trouble than it is worth - there is an explanation here: http://geekswithblogs.net/mrnat/archive/2004/09/20/11431.aspx[^]

Note that you will need a separate thread, and that you will have to take care of cross-thread Invokes to update the status bar!

"Thanks for your quick response, does it mean no simple solution for that?
how can i tell the users that the programming is accessing the database and doing the job rather than nothing shows up"


There is no simple, accurate solution, no. You can show progress if you follow the link I gave, but the only other thing you can do is to move the query to a separate thread and display on non-specific progress indicator - asynchronous SQL is also quite complicated, so I wouldn't recommend it for simple queries. It needs to be a separate thread so that the UI can be updated to actually show the progress change, otherwise your UI will "jam" in the ExecuteReader method call or whatever!
 
Share this answer
 
v2
Comments
uranusliao 23-Apr-11 4:20am    
Thanks for your quick response, does it mean no simple solution for that?
how can i tell the users that the programming is accessing the database and doing the job rather than nothing shows up
OriginalGriff 23-Apr-11 4:28am    
Answer updated
uranusliao 25-Apr-11 2:51am    
thanks, is it my first time to ask a question ,do i need to close it if i already got the answer?
OriginalGriff 25-Apr-11 2:58am    
No - you can press the "Accept Solution" button if an answer helped, or post a description of your solution for others to see as a separate answer if you worked it out yourself.

As long as a question has some answer, it is not on the "unanswered" list, which is the main thing.

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