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

Invalid attempt to read when no data is present.Invalid attempt to read when no data is present. 
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. 
Invalid attempt to read when no data is present.
Invalid attempt to read when no data is present.Exception Details: System.InvalidOperationException: Invalid attempt to read when no data is present.
Invalid attempt to read when no data is present.
Invalid attempt to read when no data is present.Source Error: 
Invalid attempt to read when no data is present.
Invalid attempt to read when no data is present.
Invalid attempt to read when no data is present.Line 106:                if (dr.HasRows) {
Invalid attempt to read when no data is present.Line 107:                    link = new Link(id);
Invalid attempt to read when no data is present.Line 108:                    link.Name = dr.GetString(1);
Invalid attempt to read when no data is present.Line 109:                    link.URL = dr.GetString(2);
Invalid attempt to read when no data is present.Line 110:                    link.Description = SqlHelper.GetStringOrNull(dr, 3);
Invalid attempt to read when no data is present. 
Invalid attempt to read when no data is present.


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

相关文章: