如何使用C#从sql server读取时间戳类型的数据?
发布时间:2020-12-15 03:57:32 所属栏目:百科 来源:网络整理
导读:我在.NET中得到结果,如下所示: var lastRowVersion = SqlHelper.ExecuteScalar(connStr,CommandType.Text,"selecttop 1 rowversion from dbo.sdb_x_orginfo order by rowversion desc"); 结果是一个字节数组[0] = 0,[1] = 0,[2] = 0,[3] = 0,[4] = 0,[5] =
我在.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); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |