Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.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/c/66.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# 如果表没有行,则引发异常_C#_.net_Vb.net - Fatal编程技术网

C# 如果表没有行,则引发异常

C# 如果表没有行,则引发异常,c#,.net,vb.net,C#,.net,Vb.net,在下面的if语句中,我需要检查第一个表中的第一行/列是否包含字符串,但如果表中没有行,则会出现异常 例外情况是: System.IndexOutOfRangeException={“位置0处没有行。”} 代码段: 'if the table has no rows then an exception happens here If myDataSet.Tables(0).Rows(0)(0).ToString <> "MyMessage" then 'do this - redi

在下面的if语句中,我需要检查第一个表中的第一行/列是否包含字符串,但如果表中没有行,则会出现异常

例外情况是:

System.IndexOutOfRangeException={“位置0处没有行。”}

代码段:

'if the table has no rows then an exception happens here
If myDataSet.Tables(0).Rows(0)(0).ToString <> "MyMessage" then


'do this - redirect

Else

 myDataSet.Tables(0).Rows(0)(0) = "no message"

End If
”如果表中没有行,则此处会发生异常
如果myDataSet.Tables(0).Rows(0)(0).ToString“MyMessage”,则
'这样做-重定向
其他的
myDataSet.Tables(0).行(0)(0)=“无消息”
如果结束

您能帮忙吗?

您应该首先检查您的表中是否有行

If myDataSet.Tables(0).Rows.Count <> 0 then

'do stuff
如果myDataSet.Tables(0).Rows.Count为0,则
“做事

您应该首先检查表中是否有行

If myDataSet.Tables(0).Rows.Count <> 0 then

'do stuff
如果myDataSet.Tables(0).Rows.Count为0,则
“做事

if..else
块包装在
if
中,如下所示:

if myDataSet.Tables(0).Rows.Count > 0 then 
//your code here
end if

if..else
块包装在
if
中,如下所示:

if myDataSet.Tables(0).Rows.Count > 0 then 
//your code here
end if

如果结果集中没有行,则无法访问
myDataSet.Tables(0).Rows(0)
。首先检查行计数:

如果myDataSet.Tables.Count为0,而myDataSet.Tables(0).Rows.Count为0,则
“你的代码
如果结束

如果结果集中没有行,则无法访问
myDataSet.Tables(0).Rows(0)
。首先检查行计数:

如果myDataSet.Tables.Count为0,而myDataSet.Tables(0).Rows.Count为0,则
“你的代码
如果结束

如果myDataSet.Tables(0).Rows(0)(0)


您应该首先通过执行
If myDataSet.Tables(0).Rows.Count>0

检查您是否有一行,因为您假设存在一行,并且使用以下语句
If myDataSet.Tables(0).Rows(0)(0)


如果myDataSet.Tables(0).Rows.Count>0,您应该首先通过执行
检查您是否有一行,异常消息是什么?您好,我更新了帖子谢谢什么异常消息?您好,我更新了帖子谢谢