如何计算执行查询所需的时间? [英] how to calcuate the time taken to execute the query?

查看:112
本文介绍了如何计算执行查询所需的时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我在针对SQL Server 2005的C#Windows应用程序中执行查询,为此,我想显示在Windows窗体上执行查询所花费的时间,该如何执行.请告诉我.

Hi,
i am execut in a query from c# windows application in against sql sever 2005, for this i want to dispaly the time taken to execute the query on the windows form, how to do it please tell me.

推荐答案

Stopwatch sw = Stopwatch.StartNew(); 
// Your query here
sw.Stop(); 
TimeSpan ts = sw.Elapsed;

// Format and display the TimeSpan value.
string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
ts.Hours, ts.Minutes, ts.Seconds,
ts.Milliseconds / 10);
Console.WriteLine("RunTime " + elapsedTime);


检查 DateTime.Now [ TimeSpan [
Check DateTime.Now[^] just before executing the query, save its value.

After the query returns, subtract the saved value from the current DateTime.Now. The result is a TimeSpan[^] that you can format very versatilely for textual output.


这篇关于如何计算执行查询所需的时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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