C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,291 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I am getting Object reference error. because of null values.
How to handle null values in LINQ Select statement
string Qtyvalues = dtQty.AsEnumerable().Select(p => p.Field<string>("KEYMATERIALS").ToString()).FirstOrDefault();
Error : object reference.
Try this or a variation
var Qtyvalues = dtQty
.AsEnumerable()
.Where(x => x["COL3"] != DBNull.Value)
.Select(p => p.Field<string>("QTY"));