Family Tree Mike
4/14/2008 2:56:00 AM
Doh! You're right. I typed into the response, not the IDE!
"Jack Jackson" wrote:
> The array declaration should be:
> Dim dataArr(oddr.FieldCount-1) As String
>
> Size specification in array declarations is the thing I dislike the
> most about VB as it is probably my most repeated mistake. Lately I
> have been trying to force myself to use the (0 To n) format to make me
> remember what that it is the upper bound, not the count.
>
> On Sun, 13 Apr 2008 10:28:01 -0700, Family Tree Mike
> <FamilyTreeMike@discussions.microsoft.com> wrote:
>
> >The equivalent would be (in my opinion):
> >
> >Dim oddr As OleDb.OleDbDataReader
> >Dim odcmd As OleDb.OleDbCommand
> >Dim odconn As OleDb.OleDbConnection
> >
> >odconn = New OleDb.OleDbConnection("connection string")
> >odcmd = New OleDb.OleDbCommand("command string", odconn)
> >oddr = odcmd.ExecuteReader
> >
> >While (oddr.Read)
> > Dim dataArr(oddr.FieldCount) As String
> > For i = 0 To oddr.FieldCount - 1
> > dataArr(i) = oddr.GetValue(i).ToString()
> > Next
> >End While
> >
> >I assume you just wanted to get a translation as the code doesn't keep the
> >values of dataArr beyond the inside of each loop.
> >
> >
> >
> >"John" wrote:
> >
> >> Hi
> >>
> >> I have below code which is written using a datatable dt. What is the
> >> equivalent code using a OleDbDataReader?
> >>
> >> For j = 0 To dt.Rows.Count - 1
> >> Dim dataArr(dt.Columns.Count) As String
> >> For i = 0 To dt.Columns.Count - 1
> >> dataArr(i) = dt.Rows(j)(i)
> >> Next
> >> Next
> >>
> >> Thanks
> >>
> >> Regards
>