How to find if a value is NULL in SQL Server using c#
.net, c#, sql, sql-server
Solution
As well as David M's method, you can also use DataRow.IsNull:
if (dr.IsNull(dc))
Problem
I would like to know which values are null in datatable in c# that is returned from ExecuteDataTable of SqlHelper class. ``` string select = "select * from testTable"; string val=""; DataTable dt=dbcon.ExecuteDataTable(select); foreach (DataRow dr in dt.Rows) { foreach (DataColumn dc in dt.Columns ) { if(dr[dc].Equals (null)) { val ="null"; } else { val = dr[dc].ToString(); } } } ``` But unfortunately I didn't find any way to do it. Please let me know if there is a way. Thank you in advance.