代码改变世界

Invalid attempt to read when no data is present.

2007-01-24 17:31  晓风残月  阅读(3104)  评论(0编辑  收藏  举报

今天在使用SqlDataReader 读取记录时,竟然出现了如下异常:

Invalid attempt to read when no data is present. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present.

Source Error: 


Line 106:                if (dr.HasRows) {
Line 107:                    link = new Link(id);
Line 108:                    link.Name = dr.GetString(1);
Line 109:                    link.URL = dr.GetString(2);
Line 110:                    link.Description = SqlHelper.GetStringOrNull(dr, 3);
 


找了半天,终于发现是自己犯糊涂了,竟然没有调用:dr.Read()