Click here to Skip to main content
15,886,032 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi All

I am writing a simple telemetry application, and need to store LapTimes in a SQL Server Database?
I have a lap class which contains the laptime, as well as other information. I am using a Stopwatch to time the Lap

What variable type should I use to store the Laptime in the Lap class, and what data type should I use in my SQL Server Database?
Posted
Comments
[no name] 15-Jun-14 11:20am    
You should use a DateTime to store your times in.

Hello friend, if you see ElapsedTicks or ElapsedMilliseconds both property returns a long value, so you have to use long variable to store the Laptime in your class. In SQL Server, you can use BIGINT to store long value.
- DD
 
Share this answer
 
Comments
DamithSL 15-Jun-14 11:43am    
Hi DD, you beat me to it :)
5wd+
Debabrata_Das 15-Jun-14 11:44am    
:)
Wes is right, but it probably needs a little more explanation.

Use a DateTime in both the class and the database - and don't store the lap time, store the timestamp instead. That way, you aren't throwing any information away: you have the start time for teh race / lap, and the end time - you can then work out the elapsed time very simply when you need it, but you can also use it to order competitors, differentiate between races, and so forth. You may never have to, but there is no real overhead (datetime is stored internally as a long integer) and comparing / calculations are really easy. If you don't then you still need to store the start and a value to indicate the duration - which is probably in milliseconds anyway - plus it needs interpretation in order to be human readable.
 
Share this answer
 
Stopwatch.Elapsed Property[^] give you a TimeSpan value and you can use it as LapTime. Create TimeSpan in your class and set it.
you can save TimeSpan.Ticks[^] in your database by using bigint data type. TimeSpan.Ticks give you long value and you can convert it back to TimeSpan by using new TimeSpan(longValFromDb)[^]
 
Share this answer
 
v2

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