3 ms·
My point is that DBNull is only an edge case with DB queries. You can avoid ever dealing with it as I've shown or use an ORM like Dapper or Entity Framework tha
by manigandham 6y ago
My point is that DBNull is only an edge case with DB queries. You can avoid ever dealing with it as I've shown or use an ORM like Dapper or Entity Framework that also handle it for you.
There's really no reason why you have to touch DBNull at all.
- recursive 6y agoI really wish that were true. DBNull is in third-party libraries. And first- and second- too. Check out this code. Dot net really wants me to use DBNull. No database in play at all. var dt = new DataTable(); dt.Columns.Add("name", typeof(string)); //dt.Columns.Add("count", typeof(int?)); // NotSupportedException: DataSet does not support System.Nullable<>. dt.Columns.Add("count", typeof(int)); var row=dt.NewRow(); row["name"] = null; //row["count"] = null; // ArgumentException: Cannot set Column 'count' to be null. Please use DBNull instead. row["count"] = DBNull.Value; dt.Rows.Add(row);