我有一个包含 7800 行的 DataTable,每行包含 3 列,如果第二列为 null,则可能有 Null 值我正在删除整行问题是,即使我删除该行,DataTable 仍然包含相同数量的行数字愿望是7800
编码 :
string query = "Select STORE_NAME, STORE_LATITUDE, STORE_LONGTITUDE "
+" From stores inner join contact_information on stores.STORE_ID=contact_information.CONTACT_ID "
+" where CONTACT_TYPE_ID=1 "
+" AND CONTACT_COUNTRY_ID="+Country
+" AND CONTACT_CASA_ID="+Casa
+" AND CONTACT_TOWN_ID="+Town;
DataTable dt = new SQLHelper(SQLHelper.ConnectionStrings.KernelConnectionString).getQueryResult(query);
dt = removeNullColumnFromDataTable(dt);
功能 :
public static DataTable removeNullColumnFromDataTable(DataTable dt)
{
for (int i = dt.Rows.Count - 1; i >= 0; i--)
{
if (dt.Rows[i][1].ToString() == null)
dt.Rows[i].Delete();
}
return dt;
}