Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
MYsql data reader if is null field c#
If is null field need to be empty

Date = rd.GetString("DATE"),

this

I have error if is empty

What I have tried:

C#
koneksi.Open();
           var rd = cmd.ExecuteReader();
           users = new List<user>();
           while (rd.Read())
           {
               users.Add(new user
               {

                    Date = rd.GetString("DATE"),

                }
                   );
           }
           rd.Close();
Posted
Updated 2-Nov-23 9:31am
v4
Comments
PIEBALDconsult 2-Nov-23 15:32pm    
You can test for NULL.
I recommend never using the Getxxx methods.

1 solution

If DATE is a nullable field then you need to test for that condition in your reading code. If the request for that field gives an error then you need to find out why. In either case you need to examine the content of your database, and also use the debugger, to find out exactly what the situation is.

And for future reference, if code produces an error, then please tell us what it is; we cannot see your screen, or read your mind.
 
Share this answer
 
v2
Comments
Stylus STYLUS 2-Nov-23 5:01am    
Thank you

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