• <i id='fii8A'><tr id='fii8A'><dt id='fii8A'><q id='fii8A'><span id='fii8A'><b id='fii8A'><form id='fii8A'><ins id='fii8A'></ins><ul id='fii8A'></ul><sub id='fii8A'></sub></form><legend id='fii8A'></legend><bdo id='fii8A'><pre id='fii8A'><center id='fii8A'></center></pre></bdo></b><th id='fii8A'></th></span></q></dt></tr></i><div id='fii8A'><tfoot id='fii8A'></tfoot><dl id='fii8A'><fieldset id='fii8A'></fieldset></dl></div>
    <tfoot id='fii8A'></tfoot>

    <small id='fii8A'></small><noframes id='fii8A'>

      • <bdo id='fii8A'></bdo><ul id='fii8A'></ul>

      <legend id='fii8A'><style id='fii8A'><dir id='fii8A'><q id='fii8A'></q></dir></style></legend>

      1. T-Sql 中的时间戳在 C# 中是什么意思?

        What does a timestamp in T-Sql mean in C#?(T-Sql 中的时间戳在 C# 中是什么意思?)

            <tbody id='fHtTi'></tbody>
          <legend id='fHtTi'><style id='fHtTi'><dir id='fHtTi'><q id='fHtTi'></q></dir></style></legend>

          <tfoot id='fHtTi'></tfoot>

            <small id='fHtTi'></small><noframes id='fHtTi'>

              <i id='fHtTi'><tr id='fHtTi'><dt id='fHtTi'><q id='fHtTi'><span id='fHtTi'><b id='fHtTi'><form id='fHtTi'><ins id='fHtTi'></ins><ul id='fHtTi'></ul><sub id='fHtTi'></sub></form><legend id='fHtTi'></legend><bdo id='fHtTi'><pre id='fHtTi'><center id='fHtTi'></center></pre></bdo></b><th id='fHtTi'></th></span></q></dt></tr></i><div id='fHtTi'><tfoot id='fHtTi'></tfoot><dl id='fHtTi'><fieldset id='fHtTi'></fieldset></dl></div>
                <bdo id='fHtTi'></bdo><ul id='fHtTi'></ul>
                  本文介绍了T-Sql 中的时间戳在 C# 中是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试开发一个模型对象来保存一个 Sql Server 行,除了 T-Sql/SqlServer 时间戳之外,我完全理解如何做到这一点.该表定义为:

                  I'm trying to develop a model object to hold a Sql Server row, and I understand perfectly how to do this except for the T-Sql/SqlServer timestamp. The table is defined as:

                  CREATE TABLE activity (
                  activity_id int
                  , ip_address varchar(39)
                  , user_id varchar(255)
                  , message_text
                  , dt timestamp
                  )
                  

                  当我将表格行解析为对象时,对于 int 或字符串,我希望执行以下操作:

                  When I resolve a table row to my object, for an int or a string I would expect to do something like:

                  ActivityID = (int)dataReader["activity_id"];
                  IPAddress = (string)dataReader["ip_address"];
                  

                  但是我该怎么处理时间戳列呢?我在任何地方都找不到时间戳"数据类型.我知道 Sql Server 将时间戳存储为 8 字节二进制文件,但这通常相当于 .NET 中的什么?

                  But what do I do about the timestamp column? There's no "timestamp" datatype that I can find anywhere. I know that Sql Server stores timestamp as an 8 byte binary, but what is this normally the equivalent of in .NET?

                  编辑添加: 一点额外信息...这是从我们大型机上的 DB2 表返回的一行,该表通过 Sql Server 视图传来.Rowversion"不是一个选项,DB2 将该列作为时间戳传递.如果时间戳和行版本相同,也许我可以将其视为一个,否则我会被时间戳卡住.

                  Edited to add: A little extra information... this is a row being returned from a DB2 table on our mainframe coming through a Sql Server view. "Rowversion" isn't an option, and DB2 is handing the column off as a timestamp. If timestamp and rowversion are identical, maybe I can treat it as one, but otherwise I'm stuck with timestamp.

                  再次编辑添加:这个项目会让我发疯.至少,这将是一次短途旅行.无论如何,是的@JoelC,这是大型机上 DB2 数据库的 Sql Server 视图.我终于找到了我们的一位 DBA,他轻蔑地解释说,当然"DB2 TIMESTAMP 将 Sql Server 视图视为日期时间.从他的语气中我猜只有菜鸟不知道这一点.这就是为什么他在实际视图中将其命名为日期时间",Duh!(我在示例中给了它一个不同的名称,以免触发对命名约定的评论——实际的数据模型图说它是一个 TIMESTAMP 并将其命名为时间戳).因此,在这种情况下,显然必须将其转换为 DateTime.我想我可能会开始考虑成为一名 DBA,这样我也可以让程序员发疯.抱歉,如果我在这个问题上误导了任何回复者——这是无意的,因为我实际上期望时间戳是一个时间戳.傻我.特别感谢微软将字节数组数据类型命名为时间戳",因为它与日期和时间无关.我不知道哪个响应标记为答案.叹息.

                  Edited again to add: This project is going to drive me nuts. It will, at least, be a short trip. Anyway, yes @JoelC this is a Sql Server view into a DB2 database on the mainframe. I was finally able to track down one of our DBAs, who explained disdainfully that "of course" a DB2 TIMESTAMP comes across as to a Sql Server view as a datetime. From his tone of voice I guess only noobs don't know this. That's why he named it "datetime" in the actual view, Duh! (I gave it a different name in my example so as to not trigger commentary on naming conventions -- the actual data model diagram says it's a TIMESTAMP and names it timestamp). So, in this event, apparently one must cast it to a DateTime. I think I may begin considering becoming a DBA so that I, too, can drive programmers crazy. Sorry if I misled any of the responders to this question -- it was unintentional, as I was actually expecting a timestamp to be, well, a timestamp. Silly me. Thanks are especially due to Microsoft for naming a byte-array datatype a "timestamp" when it has nothing to do with dates and times. I haven't the vaguest idea which response to mark as the Answer. Sigh.

                  推荐答案

                  Sql Server 时间戳数据类型名称混淆.把它想象成一个版本号真的更好—任何地方都没有日期/时间信息.事实上,从 Sql Server 2008 开始,该类型已重命名为rowversion".

                  The name of the Sql Server timestamp data type is confusing. It's really better to think of it more like a version number — there's no date/time information in there anywhere. In fact, as of Sql Server 2008 the type was renamed to "rowversion".

                  大多数情况下,您希望在 Sql Server 中输入 datetime 类型,它可以轻松映射到 C# 中的 DateTime,或者可能是 datetime2 如果您有支持它的 Sql Server 版本.关于时间戳类型的文档在这里:
                  http://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx

                  Most of the time you want the datetime type in Sql Server instead, which maps easily to DateTime in C#, or perhaps datetime2 if you have a version so Sql Server that supports it. Documentation on the timestamp type is here:
                  http://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx

                  如果你真的必须按原样映射那个时间戳列,最接近的匹配可能是普通的旧 long(或者可能是 ulong),但我不知道 sql server 如何处理字节排序或 big/little endien-ness vs C#.

                  If you really must map that timestamp column as-is, the closest match is probably plain old long (or maybe ulong), but I have no idea how sql server handles byte ordering or big/little endien-ness vs C#.

                  这篇关于T-Sql 中的时间戳在 C# 中是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  C# namespace alias - what#39;s the point?(C# 命名空间别名 - 有什么意义?)
                  Using Xpath With Default Namespace in C#(在 C# 中使用具有默认命名空间的 Xpath)
                  Generating an EDMX from a DB2 Database(从 DB2 数据库生成 EDMX)
                  IBM .NET Data Provider Connection String issue with Library List(库列表的 IBM .NET 数据提供程序连接字符串问题)
                  .NET DB2 OLEDB pre-requisites(.NET DB2 OLEDB 先决条件)
                  Referring to Code in IBM.Data.DB2 makes that Assembly Unavailable to the rest of my Solution(引用 IBM.Data.DB2 中的代码使该程序集对我的解决方案的其余部分不可用)
                    <tfoot id='jzMRv'></tfoot>

                      • <bdo id='jzMRv'></bdo><ul id='jzMRv'></ul>
                        • <small id='jzMRv'></small><noframes id='jzMRv'>

                            <legend id='jzMRv'><style id='jzMRv'><dir id='jzMRv'><q id='jzMRv'></q></dir></style></legend>
                              <tbody id='jzMRv'></tbody>
                            <i id='jzMRv'><tr id='jzMRv'><dt id='jzMRv'><q id='jzMRv'><span id='jzMRv'><b id='jzMRv'><form id='jzMRv'><ins id='jzMRv'></ins><ul id='jzMRv'></ul><sub id='jzMRv'></sub></form><legend id='jzMRv'></legend><bdo id='jzMRv'><pre id='jzMRv'><center id='jzMRv'></center></pre></bdo></b><th id='jzMRv'></th></span></q></dt></tr></i><div id='jzMRv'><tfoot id='jzMRv'></tfoot><dl id='jzMRv'><fieldset id='jzMRv'></fieldset></dl></div>