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?
nullor empty? Before you fill the table or afterwards? Also, why, what do you want to do then? Basically your question can be simplified to "How can i access a field of a DataRow via column-index" and that was asked often and is documented pretty well.The given value of type String from the data source cannot be converted to type nvarchar of the specified target column.when inserting the datatable to my sql bulk copy and Iread in this question stackoverflow.com/questions/18140012/… that is because the empty string, but even after applying the answer below, I still get that error , could you help please?