Click here to Skip to main content
15,666,844 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:

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?


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

if (DataReader.GetInt32["trials_num"] == 0)
Share this answer
See Expressions (C# Programming Guide)[^] and check the difference between = and ==.
Share this answer
You can use:

if (Convert.ToInt32(DataReader["trials_num"]) == 0)
Share this answer
phil.o 23-Dec-15 5:16am    
Convert class is rarely needed, never performant, and in this case the GetInt32 method of DataReader class is the way that should be used.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900