Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/sql-server-2008/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#奇怪的数据表nullreferenceexception_C#_Datatable - Fatal编程技术网

c#奇怪的数据表nullreferenceexception

c#奇怪的数据表nullreferenceexception,c#,datatable,C#,Datatable,我在这里的最后一行得到了这个例外 当我检查行的内容时不为空 我做错了什么?当您尝试在null对象上调用成员或方法时(换句话说,当您在null对象上使用.operator时),通常会发生NullReferenceException。我的最佳猜测是,dt_final或者其他用户建议的dttemp1为空。通常在尝试对空对象调用成员或方法时(换句话说,当对空对象使用.operator时),会发生NullReferenceException。我最好的猜测是,dtu final或者其他用户建议的dttemp

我在这里的最后一行得到了这个例外

当我检查
行的内容时
不为空


我做错了什么?

当您尝试在null对象上调用成员或方法时(换句话说,当您在null对象上使用.operator时),通常会发生
NullReferenceException
。我的最佳猜测是,
dt_final
或者其他用户建议的
dttemp1
为空。

通常在尝试对空对象调用成员或方法时(换句话说,当对空对象使用.operator时),会发生
NullReferenceException
。我最好的猜测是,
dtu final
或者其他用户建议的
dttemp1
是空的。

dtu final
肯定是空的,只是因为没有其他东西可以。问题是为什么它只在最后一行抛出错误。原因是
dttemp.Rows
为空,并且不会执行first
foreach
dtu final
绝对为空,因为其他任何内容都不能执行。问题是为什么它只在最后一行抛出错误。原因是
dttemp.Rows
为空,并且未执行first
foreach

是否可能dtu final或dttemp或dttemp1为空?显然,您访问的某个变量未设置为有效的对象引用。也许是dt_final,也许是ImportRow函数中的某个地方。很难从这里猜测。@每个人如果dt_final为空,那么我将在第二行得到此异常,而不是在最后一行,而不是让所有人猜测,为什么不设置一个断点并在调试器中运行它呢?有可能dtu final或dttemp或dttemp1为空吗?显然,您访问的某个变量没有设置为有效的对象引用。也许是dt_final,也许是ImportRow函数中的某个地方。很难从这里猜测。@每个人如果dt_final为null,那么我将在第2行得到此异常,而不是在最后一行。老实说,与其让所有人都猜测,为什么不设置一个断点并在调试器中运行此操作?如果dt_final为null,那么我将在第2行得到此异常,而不是在最后一行得到此异常不一定。如果dttemp.Rows为空,则第一个for循环将不会运行。这可能是一个特别棘手的例外。很多时候,您需要一步一步地仔细跟踪代码以跟踪问题。如果dt_final为null,那么我会在第2行得到此异常,而不是在最后一行,不一定。如果dttemp.Rows为空,则第一个for循环将不会运行。这可能是一个特别棘手的例外。很多时候,您需要一步一步地仔细跟踪代码以跟踪问题。
foreach (DataRow row in dttemp.Rows)
    dt_final.ImportRow(row);
foreach (DataRow row in dttemp1.Rows)
    dt_final.ImportRow(row);