473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Datatable equivalent code with OleDbDataReader

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
Jun 27 '08 #1
4 2617
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
Jun 27 '08 #2
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
<Fa************@discussions.microsoft.comwrote:
>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
Jun 27 '08 #3
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
<Fa************@discussions.microsoft.comwrote:
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
Jun 27 '08 #4
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" <in**@nospam.infovis.co.ukschreef in bericht
news:ex**************@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

Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: haiQ | last post by:
I'm a new at C# - so please forgive my ignorance. The following 2 snippets of code seem to be fairly equivalent. Is there any advantage to using 1 over the other? Example 2 seems to be much more...
0
by: tlemcenvisit | last post by:
Hello I translated this code (witch convert an image to grayscale) from C#.NET to C++.NET The C#.NET code is : private void GrayScale(Bitmap b) { BitmapData bmData = b.LockBits(new...
5
by: tlemcenvisit | last post by:
Hello in C# : Partial type definitions allow the definition of a class, struct or interface to be split into multiple files. I'd like to have the equivalent keyword of partial in VC++ does...
4
by: Geoff Jones | last post by:
Hi Can anybody tell me the equivalent code in VB for the following? public static void copyADataRow(DataRow objSrcRow, DataRow objTargetRow) { int i=0; for each(object item in...
4
by: guy | last post by:
I am binding a datatable to a WinForms grid control but for some reason the GridTableStyle is being ignored, the data just displays as if no TableStyle was set up I have also tried changing the...
2
by: SalamElias | last post by:
Hi, I managed to transform a C# class to VB except the following portion of the code if(dgItem.Cells.Controls.Count > 0 && dgItem.Cells.Controls is LinkButton) ..dgItem is a datagrid item. What...
4
by: renaysingh | last post by:
Hi I am new to C programming. What is the best way to get Matlab's any and all functions working in C? Is there a library available? Which is the best for speed? For reference the...
3
by: geobas | last post by:
It's only a simple line of VB6 code WebBrowser1.Navigate App.Path & "\index.html" l have VS2005 .How can l write this in .NET Thanks in advance for replies
3
by: John | last post by:
Hi Sorry, I am new to this. Is there a way to cerate a datatable from a OleDbDataReader? Thanks Regards
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.