Marco Dinatsoli Marco Dinatsoli - 1 month ago 10
C# Question

c# check the empty or null value in all datatable values

I have a

DataTable
and I initialize it like this:

dataTable = new DataTable();
dataTable.Clear();
for (int i = 0; i < labels.Length; i++)
{
dataTable.Columns.Add(MyCSVReaderFinal.labels[i]);
}
return dataTable;


where
label
is array of string like this:

private static string[] labels = { "FARM ID", "FARM OWNER ARABIC", "FARM NUMBER",
"FARM MOBILE", "EMAR NAME ARABIC", "EMARA ID", "AREA NAME ARABIC", "AREA ID",
"REGION NAME ARABIC", "REGION ID", "RECEIVING CENTER NAME ARABIC",
"RECEIVING CENTER ID", "KHALAS", "FARDH", "OTHER LULU", "KHENAIZI", "BOUMAAN",
"BARHI", "JESH KHARMA", "REZIZ", "JABRI", "ANBARET AL-MADINA", "SHISHI",
"DABBAS", "NABTET SAIF", "KHEDRAWI", "HILALI", "MAKTOUMY", "NAMISHI",
"SULTANAH", "BAQLAT AL-TAWAA", "BAQLAT AL-DAHLA", "BAQLAT AL-RARENJA",
"SUKARY", "SAQEI", "ABU ZEBED", "MAJDOUL", "SHABIBI", "YOUWANI", "YARDI",
"KHADI", "HATIMI", "NEGHAL", "OTHER SAYER", "TOTAL FRUCTIFEROUS",
"TOTAL UN FRUCTIFEROUS", "TOTAL AFHAL", "GENERAL TOTAL", "SENIOR SUPERVISORS",
"ASSISTANT", "DATA ENTRY", "FARM ONWER OR BEHALF" };


I want to check the null of empty string of every value into that data table:

I tried this:

for (int i = 0; i < dt.Rows.Count; i++) {
for (int j = 0; j < dt.Columns.Count; j++) {
if(string.IsNullOrEmpty(dt.Rows[i].)){}
}
}


but as you see, I tried this:
dt.Rows[i].
but I didn't know how to get the value

Could you help me please?

Answer

Use the indexer

dt.Rows[i][j] != null && string.IsNullOrEmpty(dt.Rows[i][j].ToString())