Datareader无法正常工作 [英] Datareader not working

查看:87
本文介绍了Datareader无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我在使用datareader时遇到异常是代码


Me.SqlConnection1.Open()

Me.SqlReservationCheck.P​​arameters( " @ Ref")。值= Ref

Dim Reader As SqlClient.SqlDataReader = _

Me.SqlReservationCheck.ExecuteReader()

Dim我作为整数()

Dim Index As Integer = 0

如果Reader.HasRows那么

而Reader.Read()

ReDim Preserve I(指数)

我(指数)= Reader.Item(0)

指数+ = 1

结束虽然

结束如果

Reader.Close()

Me.SqlConnection1.Close()


当我执行While Reader.Read()命令时,读者给出错误

但是如果Reader.HasRows然后返回true,有人可以帮我这个


-

后来


Scott Richards

Hi I am getting a exception while using a datareader here is the code

Me.SqlConnection1.Open()
Me.SqlReservationCheck.Parameters("@Ref").Value = Ref
Dim Reader As SqlClient.SqlDataReader = _
Me.SqlReservationCheck.ExecuteReader()
Dim I As Integer()
Dim Index As Integer = 0
If Reader.HasRows Then
While Reader.Read()
ReDim Preserve I(Index)
I(Index) = Reader.Item(0)
Index += 1
End While
End If
Reader.Close()
Me.SqlConnection1.Close()

When I execute the While Reader.Read() command the reader gives false
But the If Reader.HasRows Then returns true could someone help me with this

--
Later

Scott Richards

推荐答案

" Scott理查兹" <钪*********** @ discussions.microsoft.com>在消息中写道

news:38 ********************************** @ microsof t.com ...
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
嗨我在这里使用datareader时遇到异常是代码
Hi I am getting a exception while using a datareader here is the code




你得到了哪个例外,它会发生什么变化?


我真的不知道你希望有人能够帮助你给你

少量的您提供的信息。


John Saunders



Which exception do you get, and what line does it happen on?

I really don''t know how you expect anyone to be able to help you given the
small amount of information you''ve provided.

John Saunders


对于John的信息缺乏感到抱歉,当我写这篇文章时我花了5个小时来研究这个问题&很沮丧&累了。


问题是,当我运行datareader.read命令时,循环不会因为命令错误而导致错误


我已经通过运行datareader.read命令检查了它,而没有

while loop&信息在读者中,你建议我做什么?


从我所做的所有阅读中我发现没有像

这个。


感谢您的帮助

-

后来Scott Richards


John Saunders写道:
Sorry for the lack of information John, by the time I wrote this I had spent
5 hours researching the problem & was quite frustrated & tired.

The problem is that when I run the datareader.read command the loop does not
intiate because the command gives false

I have checked it by running the datareader.read command without without the
while loop & the information is in the reader, what do you suggest I do?

From all the reading on the subject I have done I have found nothing like
this.

Thank you for your help
--
Later Scott Richards

"John Saunders" wrote:
" Scott Richards" <钪*********** @ discussions.microsoft.com>在消息中写道
新闻:38 ********************************** @ microsof t.com。 ..
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:38**********************************@microsof t.com...
嗨我在使用datareader时遇到异常是代码
Hi I am getting a exception while using a datareader here is the code



你得到了哪个例外,它会发生什么行?

我真的不知道你希望有什么人能够帮助你提供你提供的少量信息。

John桑德斯



Which exception do you get, and what line does it happen on?

I really don''t know how you expect anyone to be able to help you given the
small amount of information you''ve provided.

John Saunders



" Scott Richards" <钪*********** @ discussions.microsoft.com>在留言中写道

新闻:E7 ********************************** @ microsof t.com ...
"Scott Richards" <Sc***********@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
抱歉缺少信息约翰,在我写这篇文章的时候我已经花了5个小时来研究这个问题&很沮丧&累了。

问题是,当我运行datareader.read命令时,循环确实没有启动,因为命令给出了错误
Sorry for the lack of information John, by the time I wrote this I had
spent
5 hours researching the problem & was quite frustrated & tired.

The problem is that when I run the datareader.read command the loop does
not
intiate because the command gives false




在这种情况下,我首先假设DataReader正常工作

。如果你从这个假设开始,你就会想知道为了使一个功能正常的DataReader能够立即返回false,你可能已经做了多少b $ b。例如,您确定您的查询是否正确?
是否正确?如果它需要参数,它们是否正确?例如,也许

你有一个带有尾随空格的字符串参数。


John Saunders



In a case like this, I would first assume that the DataReader is working
correctly. If you start with that assumption, you''re left to wonder what you
could possibly have done to make a correctly-functioning DataReader to
return false right away. For instance, are you certain that your query is
correct? If it requires parameters, are they correct? For instance, maybe
you''ve got a string parameter which has trailing spaces.

John Saunders

这篇关于Datareader无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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