以下内容对我有用!由于早期值不完整,因此空引用阻塞了我的代码。
希望这对某人有帮助!!
foreach (var row in doc.DocumentNode.SelectNodes("//tr[td]"))
{
string pos = "0";
pos = row.SelectSingleNode("td//input")?.Attributes["name"].Value;
string injid = row.SelectSingleNode("td//input")?.Attributes["value"].Value;
table.Rows.Add((row.SelectNodes("td").Select(td => td.InnerText).ToArray()));
if (string.IsNullOrEmpty(pos))
{
}
else
{
int ronum = table.Rows.Count - 1;
DataRow dr = table.Rows[ronum];
dr[9] = pos;
}
if (string.IsNullOrEmpty(injid))
{
}
else
{
int ronum = table.Rows.Count - 1;
DataRow dr = table.Rows[ronum];
dr[10] = injid;
}
}