当没有数据存在时,invalide尝试读取 [英] invalide attempt to read when no data is present
本文介绍了当没有数据存在时,invalide尝试读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在验证一个列日期大于或小于今天日期的数据库。
我的代码如下
I am validating database of one column date greater than or lesser than today date.
My code as follows
SQl = "select sp_issu_dt from student_professional
where stud_id = " + id + " and pm_prof_code = 'medrep'";
drmedical = SCon.ReadSql(SQl);
if (drmedical.Read()&& drmedical.HasRows &&(Convert.ToDateTime(drmedical[0]) > Convert.ToDateTime(GetDate)))
{
med = "himt";
}
当我运行上面的代码时显示如下错误
无效尝试阅读当没有数据时。
当我在drmedical [0]中执行时,未检索到值。
请帮我解决我犯的错误。
When i run the above code shows error as follows
Invalid attempt to read when no data is present.
When i execute in drmedical[0] value is not retrieved.
Please help me what is the mistake i made.
推荐答案
你必须打电话给DataReader.Read 首先获取结果:
You have to call DataReader.Read first to fetch the result:
string SQl = "select sp_issu_dt from student_professional
where stud_id = " + id + " and pm_prof_code = 'medrep';
SqlCommand cmd = new SqlCommand(SQL);
SqlDataReader dr = cmd.ExecuteReader();
//drmedical = SCon.ReadSql(SQl);
if (dr.Read() && dr.HasRows &&(Convert.ToDateTime(drmedical[0])
// ... and so long
这篇关于当没有数据存在时,invalide尝试读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文