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
C#
txtDataTest.Text = rdr["DataTestSSM"] == DBNull.Value ? "-" : ((DateTime)(rdr["DataTestSSM"]).ToString("dd-MM-yyyy"));What am I doing wrong?


Jithu ThomasRank #437 · 5.7K reputationPosted Jun 22, 2024, 4:51 AM EDT
You can correct the same with the following code
txtDataTest.Text = rdr["DataTestSSM"] == DBNull.Value ? "-" : ((DateTime)rdr["DataTestSSM"]).ToString("dd-MM-yyyy");