如何使用进度条指示数据库进度 [英] how to use progress bar to indicate database progress

查看:131
本文介绍了如何使用进度条指示数据库进度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用进度条来指示Windows窗体正在访问数据库并正在处理查询,但是我不知道如何设置最大值,因为我不知道数据库将花费多长时间进行查询,任何人都可以在这里阐明一下,谢谢.

干杯

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

推荐答案

否.我们不能.我们也不知道.

一根线多长?

您要获取多少数据?您的服务器有多快?连接是什么样的?您返回的是简单查询还是复杂的存储过程的结果?查询时您的服务器负载如何?这些因素和其他因素都会影响所花费的时间.

您可以强制SQL Server向您提供进度指示,但这并不简单,并且可能比值得的麻烦还多-此处有一个解释:http://geekswithblogs.net/mrnat/archive/2004/09/20/11431.aspx [

没有简单,准确的解决方案,没有.如果您遵循我给出的链接,则可以显示进度,但是唯一可以做的是将查询移至单独的线程并在非特定进度指示器上显示-异步SQL也非常复杂,因此我不会''推荐它用于简单查询.它需要是一个单独的线程,以便可以更新UI来实际显示进度更改,否则您的UI将在ExecuteReader方法调用或任何其他操作中阻塞"!
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!


这篇关于如何使用进度条指示数据库进度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆