它必须是一个bug或者我疯了! [英] Its gotta be a bug or I'm crazy!

查看:75
本文介绍了它必须是一个bug或者我疯了!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从SQL Server 2000表中检索6个字段,其中包含以下sql

语句。


SQL =" select Field1,field2,field3, table4中的field4,field5,field6"

最后一个字段(字段6)在表中定义为ntext。

我将它们放在名为dr的datareader中。 br />
Dim dc1 As New OleDbCommand(Sql,conn)

Dim dr1 As OleDbDataReader =

dc.ExecuteReader(CommandBehavior.SequentialAccess)

代码在那里工作正常。

然后我想读取datareader的内容并将争议写入

a streamwriter sw1

但是当我点击Retval = dr1.GetBytes(5,StartIndex,outbyte,

0,bufferSize)下面的行时

或者如果我尝试dr1.getvalue(5)或者在我的datarow对象中引用第6个
字段的任何其他命令我得到了

一个错误索引超出了数组的范围,但它是一个六item

基于零的数组,所以我使用的值5是正确的

当我在服务器2000查询分析器中运行SQL语句时,我得到了
预期的结果。


如果这不是一个错误,任何人都可以解释我做错了吗?


感谢您的帮助和Mery圣诞节和新年快乐,对不起,如果

'在政治上不正确;-)

bob


Do while dr1.Read()


如果不是IsDBNull(dr1.GetValue(0))那么

sw1.WriteLine(Tab&标签& "< Inconsistencies>")

sw1.WriteLine(Tab& Tab& Tab&"< Field1>"&

dr1。 GetDateTime(0).ToString&"< / Field1>")

sw1.WriteLine(Tab& Tab& Tab&"< Field2>"&

dr1.GetString(1)&"< / Field2>")

sw1.WriteLine(Tab& Tab& Tab&"< Field3>"&

dr1.GetValue(2).ToString&"< / Field3>")

sw1.WriteLine(Tab& Tab) & Tab&"< Field4>"&

dr1.GetString(3)&"< / Field4>")

sw1 .WriteLine(Tab& Tab& Tab&"< Field5>"&

dr1.GetString(4)&"< / Field5>")

Retval = dr1.GetBytes(5,StartIndex,outbyte,0,

bufferSize)

执行Retval = bufferSize

sw1.Write(outbyte)

sw1.Flush()


''将起始索引重新定位到最后一个缓冲区结束

并填充缓冲区。

StartIndex + = bufferSize

Retval = dr1.GetBytes(5,StartIndex,

outbyte,0,bufferSize)

循环


''写剩下的缓冲。

''''sw1.Write(outbyte,0,Retval - 1)

''''bw.Flush()

sw1.Write(CrLf)


''sw1.WriteLine(Tab&标签& Tab&

"< Inconsistency>" &安培; dr1.Item(5)& "< / Inconsistency>")

sw1.WriteLine(Tab& Tab&"< / Inconsistencies>")

结束如果

循环


然后我读了eac

I am retrieving 6 fields from an SQL server 2000 table with following sql
statement.

SQL = "select Field1, field2, field3, field4, field5, field6 from table1"

Last field ( field 6) is defined in table as ntext.
I put them in datareader named dr.
Dim dc1 As New OleDbCommand(Sql, conn)
Dim dr1 As OleDbDataReader =
dc.ExecuteReader(CommandBehavior.SequentialAccess)
Code works fine to there.
Then I want read the contents of the datareader and write the contens to
a streamwriter called sw1
But when I hit the line below Retval = dr1.GetBytes(5, StartIndex, outbyte,
0, bufferSize)
or if I try dr1.getvalue(5) or any other command that references the 6th
field in my datarow object I get
an error "Index was outside the bounds of the array", yet it is a six item
zero based array, so the value 5 I use is correct
and when I run the SQL statement in the server 2000 query analyzer I get te
expected results.

Can anyone explain what I''m doing wrong if this is not a bug?

Thanks for your help and Mery christmas and happy new year and sorry if
that''s not politically correct ;-)
bob

Do While dr1.Read()

If Not IsDBNull(dr1.GetValue(0)) Then
sw1.WriteLine(Tab & Tab & "<Inconsistencies>")
sw1.WriteLine(Tab & Tab & Tab & "<Field1>" &
dr1.GetDateTime(0).ToString & "</Field1>")
sw1.WriteLine(Tab & Tab & Tab & "<Field2>" &
dr1.GetString(1) & "</Field2>")
sw1.WriteLine(Tab & Tab & Tab & "<Field3>" &
dr1.GetValue(2).ToString & "</Field3>")
sw1.WriteLine(Tab & Tab & Tab & "<Field4>" &
dr1.GetString(3) & "</Field4>")
sw1.WriteLine(Tab & Tab & Tab & "<Field5>" &
dr1.GetString(4) & "</Field5>")
Retval = dr1.GetBytes(5, StartIndex, outbyte, 0,
bufferSize)
Do While Retval = bufferSize
sw1.Write(outbyte)
sw1.Flush()

'' Reposition the start index to the end of
the last buffer and fill the buffer.
StartIndex += bufferSize
Retval = dr1.GetBytes(5, StartIndex,
outbyte, 0, bufferSize)
Loop

'' Write the remaining buffer.
''''sw1.Write(outbyte, 0, Retval - 1)
''''bw.Flush()
sw1.Write(CrLf)

''sw1.WriteLine(Tab & Tab & Tab &
"<Inconsistency>" & dr1.Item(5) & "</Inconsistency>")
sw1.WriteLine(Tab & Tab & "</Inconsistencies>")
End If
Loop

Then I read eac

推荐答案

你' '应该使用GetString()或GetChars()


参考:
http://msdn.microsoft.com/library/de...kdatatypes.asp


祝你好运
You''re supposed to use GetString() or GetChars()

Refer to:
http://msdn.microsoft.com/library/de...kdatatypes.asp

Good luck


为了什么?


" Rulin香港" <儒******* @ discussions.microsoft.com>在消息中写道

新闻:80 ********************************** @ microsof t.com ...
For what?

"Rulin Hong" <Ru*******@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
你应该使用GetString()或GetChars()

请参阅:
http://msdn.microsoft。 com / library / de ... kdatatypes.asp
祝你好运
You''re supposed to use GetString() or GetChars()

Refer to:
http://msdn.microsoft.com/library/de...kdatatypes.asp
Good luck



他说你必须使用GetString()或者用于SQL ntext数据类型的
datareader的GetChars()方法。

您似乎正在使用GetBytes,它用于图像SQL数据类型


BTW:很棒的链接Rulin!


Greg


" Noozer" <做******* @ me.here>在消息中写道

news:u7 ************** @ TK2MSFTNGP12.phx.gbl ...
He is saying you must use the GetString() or GetChars() method of the
datareader for SQL ntext datatypes.

You appear to be using GetBytes, which is for is for the image SQL datatype

BTW: Great link Rulin!

Greg

"Noozer" <do*******@me.here> wrote in message
news:u7**************@TK2MSFTNGP12.phx.gbl...
为了什么?

Rulin Hong <儒******* @ discussions.microsoft.com>在消息中写道
新闻:80 ********************************** @ microsof t.com。 ..
For what?

"Rulin Hong" <Ru*******@discussions.microsoft.com> wrote in message
news:80**********************************@microsof t.com...
你应该使用GetString()或GetChars()

参考:
You''re supposed to use GetString() or GetChars()

Refer to:


http://msdn.microsoft。 com / library / de ... kdatatypes.asp


祝你好运

Good luck




这篇关于它必须是一个bug或者我疯了!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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