0

How can i escape this error? I cant seem to use the IF ELSE clause, in my query not all has values so other columns will have "NULL" values. I want to display "NULL" values as "0". How can i do it?

Here is my code

while(readers.Read())
            {       
                b = readers.GetInt32(0);
                if (b == 0 || b == null)
                {
                    gvModal.Rows[y].Cells[6].Text = "0";
                }
            }

is the if statement correct?

Maverick
  • 1,396
  • 5
  • 22
  • 42
Jedi Ablaza
  • 171
  • 15
  • Make b as Nullable i.e `Int32? b` – Jaydip Jadhav Jul 26 '16 at 06:32
  • Linked question is about `SqlDataReader`, but you can use this approach for any implementation of `IDataReader` as well. Note, that SQL `NULL`, C# `null`, and `0` (zero) are not the same things. Maybe, this will fool your user. – Dennis Jul 26 '16 at 06:34

0 Answers0