MYsql data reader if is null field c#
If is null field need to be empty
Datum = rd.GetString("DATUM"),
this
I have error if is empty
C#
koneksi.Open();
var rd = cmd.ExecuteReader();
users = new List();
while (rd.Read())
{
users.Add(new user
{
Datum = rd.GetString("DATUM"),
}
);
}
rd.Close();
Khoday AkileshRank #638 · 3.8K reputationPosted Nov 2, 2023, 5:17 AM EDT
Could you share the error, which you are getting.
Jignesh KumarRank #91 · 22.9K reputationPosted Nov 2, 2023, 5:45 AM EDT
Hello,
What is datatype of "Datum" in user model ?
Khoday AkileshRank #638 · 3.8K reputationPosted Nov 2, 2023, 5:53 AM EDT
string? Datum = rd.GetString("DATUM") != "" ? rd.GetString("DATUM") : null;
Goran BibicRank #993 · 2K reputationPosted Nov 2, 2023, 5:37 AM EDT
Error
System.InvalidCastException: 'Specified cast is not valid.'