if语句与datareader [英] if statement with datareader

查看:62
本文介绍了if语句与datareader的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图测试我的sql表中字段的值是否为0.这是一个整数字段,我正在使用数据读者!



 if(DataReader.GetInt32 [trials_num] = 0)





这是错误的,我怎么测试呢?



谢谢

解决方案

在C#中,使用 double == operator。 [< a href =https://msdn.microsoft.com/en-us/library/53k8ybth.aspxtarget =_ blanktitle =New Window> ^ ]



 if(DataReader.GetInt32 [trials_num] == 0)


参见表达式(C#编程指南) [ ^ ]并检查 = 和<$ c之间的区别$ C> == 。


您可以使用:



  if (Convert.ToInt32(DataReader [  trials_num])==  0 


Hi,

I am trying to test if the value of a field in my sql table is = 0. it is an integer field and i am using data reader!

if (DataReader.GetInt32["trials_num"] = 0)



this is wrong so how can i test it?

thanks

解决方案

In C# equality is indicated with a double == operator.[^]

if (DataReader.GetInt32["trials_num"] == 0)


See Expressions (C# Programming Guide)[^] and check the difference between = and ==.


You can use:

if (Convert.ToInt32(DataReader["trials_num"]) == 0)


这篇关于if语句与datareader的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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