如何在课堂和数据库中存储笔记本时间? [英] How Do I Store Laptimes In A Class And Database?

查看:57
本文介绍了如何在课堂和数据库中存储笔记本时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



我正在编写一个简单的遥测应用程序,需要将LapTimes存储在SQL Server数据库中吗?

我有一个包含laptime的圈级,以及其他信息。我正在使用秒表为时间计时



我应该使用什么变量类型来在Lap类中存储Laptime,以及我应该在SQL中使用什么数据类型服务器数据库?

解决方案

你好朋友,如果你看到 ElapsedTicks ElapsedMilliseconds 两个属性都返回一个long值,因此你必须使用 long 变量来存储你班级的Laptime。在SQL Server中,您可以使用 BIGINT 来存储长值。

- DD


Wes是对的,但它可能需要一个更多解释。



在类和数据库中使用DateTime - 并且不存储单圈时间,而是存储时间戳。这样,你就不会丢掉任何信息:你有比赛/圈的开始时间和结束时间 - 你可以在需要的时候非常简单地计算出经过的时间,但你也可以用它来订购竞争对手,区分比赛等等。您可能永远不会,但没有实际开销(日期时间内部存储为 long 整数),并且比较/计算非常简单。如果你不这样做,你仍然需要存储开始和一个值来指示持续时间 - 无论如何可能是毫秒 - 加上它需要解释才能是人类可读的。


Stopwatch.Elapsed Property [ ^ ] 给你一个TimeSpan值,您可以将其用作LapTime。在您的班级中创建TimeSpan并进行设置。

你可以保存 TimeSpan.Ticks [ bigint 数据类型在数据库中显示> ^ TimeSpan.Ticks 为您提供 long 值,您可以使用new TimeSpan(longValFromDb) [< a href =http://msdn.microsoft.com/en-us/library/zz841zbz(v=vs.110).aspx\"target =_ blanktitle =New Window> ^ ]

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?

解决方案

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


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.


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)[^]


这篇关于如何在课堂和数据库中存储笔记本时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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