R
RD
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
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