开发者

c# strange datatable nullreferenceexception

foreach (DataRow row in dttemp.Rows)
    dt_final.ImportRow(row);
foreach (D开发者_运维问答ataRow row in dttemp1.Rows)
    dt_final.ImportRow(row);

i am getting this exception on the LAST line here

when i check the contents of row are NOT null

what am i doing wrong?


A NullReferenceException occurs usually when you try to invoke a member or method on a null object (in other words, when you use the . operator on something that is null). My best guess is that dt_final or perhaps dttemp1 as other users have suggested is null.


dt_final is definitely null, just because nothing else can be. The question is why it throws error only at last line. Reason is that dttemp.Rows is empty and first foreach is not executed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜