行/列的数据不存在. [英] No data exists for the row/column.

查看:126
本文介绍了行/列的数据不存在.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在网上出现错误

行/列的数据不存在.提前thx ....时间是数据库中的列

字符串mystring4 = drNameShow ["Time"].ToString();

on the line error come as

No data exists for the row/column. thx in advance....time is column in database

string mystring4 = drNameShow["Time"].ToString();

推荐答案

尝试下面的代码
try below code
if(drNameShow["Time"] != System.DBNull.Value)
   {
      string mystring4= drNameShow["Time"].ToString();
   }
   else
   {
       string mystring4 = "NULL";
   }


在尝试访问该行中的列之前,检查数据读取器是否有任何行. 读取将返回布尔值,指示是否有任何可用值.

例如
Check if the datareader has any rows before trying to access the columns in that row.
Read returns a bool indicating if there is any value available.

e.g.
if (drNameShow.Read())    
 { //processing here  }




试试下面的代码.可能会对您有所帮助.


try the following code. It may be help you.
if (!string.IsNullOrEmpty(drNameShow["Time"].ToString()))
{
string mystring4= drNameShow["Time"].ToString();
}
else
{
string mystring4 = string.Empty;
}



谢谢,
Viprat



Thanks,
Viprat


这篇关于行/列的数据不存在.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆