Marius Vasile

Marius Vasile

  • 593
  • 1.8k
  • 135.5k

Handle null DateTime in SQLDataReader

Jun 22 2024 7:57 AM

In the table, DateTime field DataTestSSM is not null. When I try to get data from reader and handle the null value is not working. I tried with

 

txtDataTest.Text = rdr["DataTestSSM"] == DBNull.Value ? "-" : ((DateTime)(rdr["DataTestSSM"]).ToString("dd-MM-yyyy"));

What am I doing wrong?


Answers (1)