变得有点距离的SqlServer到C# [英] Getting a Bit from SqlServer into c#
本文介绍了变得有点距离的SqlServer到C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从一个SQL Server有点成C#。我尝试不同的充解决方案,如:
I need to get a Bit from a sql server into c#. I tried differnt solutions like:
bool active = rdr.GetSqlBinary(5);
Int16 active = rdr.GetSqlBinary(5);
但无法找到任何方式来获得该位。
有人可以给个例子吗?
But can't find any way to get the Bit. Can someone give an example?
推荐答案
如果您确信列值永远不会 NULL
那么下面会做的伎俩:
If you're certain that the column values will never be NULL
then the following will do the trick:
bool active = rdr.GetBoolean(rdr.GetOrdinal("Active"));
如果这是可能的 NULL
值可能是返回:
If it's possible that NULL
values might be returned:
int oActive = rdr.GetOrdinal("Active");
bool? active = rdr.IsDBNull(oActive) ? (bool?)null : rdr.GetBoolean(oActive);
这篇关于变得有点距离的SqlServer到C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文