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

RE: Datatable equivalent code with OleDbDataReader by FamilyTreeMike

FamilyTreeMike
Sun Apr 13 12:28:01 CDT 2008

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

Re: Datatable equivalent code with OleDbDataReader by Jack

Jack
Sun Apr 13 14:27:13 CDT 2008

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

Re: Datatable equivalent code with OleDbDataReader by FamilyTreeMike

FamilyTreeMike
Sun Apr 13 21:56:00 CDT 2008

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
>

Re: Datatable equivalent code with OleDbDataReader by Cor

Cor
Sun Apr 13 22:43:03 CDT 2008

John,

It would be something

If you eat apples you cannot peal them in the same way as a banana

To get information from a datatable has nothing to do with get information
from a database, moreover, the fill command by instance uses a datareader to
fill the datatable.

Cor

"John" <info@nospam.infovis.co.uk> schreef in bericht
news:exW1JKXnIHA.3532@TK2MSFTNGP05.phx.gbl...
> 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
>
>