如何使用C#从sql server读取时间戳类型的数据?

前端之家收集整理的这篇文章主要介绍了如何使用C#从sql server读取时间戳类型的数据?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在.NET中得到结果,如下所示:
var lastRowVersion = sqlHelper.ExecuteScalar(connStr,CommandType.Text,"select
top 1 rowversion from dbo.sdb_x_orginfo order by rowversion desc");

结果是一个字节数组[0] = 0,[1] = 0,[2] = 0,[3] = 0,[4] = 0,[5] = 0,[6] = 30,[7 ] = 138,但sql Server中的结果为0x0000000000001E8A.

如何在.NET中获取值“0x0000000000001E8A”?

解决方法

如果您只想将byte []转换为System.Int64(又名long),则使用 BitConverter.ToInt64
sqlBinary binary = /* ... */;
long value = BitConverter.ToInt64(binary.Value,0); // 0 is the start index in the byte array

要将其显示为十六进制字符串,可以使用X format specifier,例如:

Console.WriteLine("Value is 0x{0:X}.",value);
原文链接:https://www.f2er.com/csharp/93221.html

猜你在找的C#相关文章