Today when doing a data export, found that the exported data is empty causes the conversion error, how do we determine the DataTable table column data Book is empty? Please look at the following code ...
<summary>
</summary>
<param name= "FilePath" > Exported path </param>
<param name= "DT" > Data to be exported </param>
Private void Export (string FilePath, DataTable DT)
{
.....
for (int i=0;i<dt. rows.count;i++)
{
Before you judge an old error: object is not referenced to the display column
Because dt[i]["OrderNo"] is empty at all, cannot tostring ();
String orderno=dt[i]["OrderNo"]. Tostring () = = ""? " ":d T. row[i]["OrderNo"]. Tostring ();
Using the ternary operator, I believe we all understand! Conditions? Result 1: Result 2
String orderno=dt[i]["OrderNo"]==dbnull. Value? " ":d T. row[i]["OrderNo"]. Tostring ();
}
}
DataTable determines if the column is empty! Utility