Click here to Skip to main content
16,019,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

C#
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);
 
Share this answer
 
v2
Comments
lukeer 18-Oct-12 5:06am    
IIRC, the Stopwatch is more accurate than what I suggested.
Sushil Mate 18-Oct-12 5:30am    
:)
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.
 
Share this answer
 

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