Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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!

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


this is wrong so how can i test it?

thanks
Posted

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

C#
if (Convert.ToInt32(DataReader["trials_num"]) == 0)
 
Share this answer
 
Comments
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.
In C# equality is indicated with a double == operator.[^]

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

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