Hi,
Does anyone know how to read the contents of a datareader into an
array? The datareader will only hold one field called CuttingID. Can
anyone help me including how i would declare the array etc... I have
the
While dr.Read()
End While
part but don't know how to go about populating the array. Thanks in
advance
James 5 16135
Does it have to be an Array or could you use a List <Of Whatever>? If
you use a List you just need to use it's .Add method to insert the
data.
Anyways, here's some air code for the array:
Dim str(1) as String
while dr.Read()
str(str.Length - 1) = CStr(dr.GetValue(0))
Redim str(str.Length)
end while
That should be close to what you need to do to use an array.
Thanks,
Seth Rowe
jimmy wrote:
Hi,
Does anyone know how to read the contents of a datareader into an
array? The datareader will only hold one field called CuttingID. Can
anyone help me including how i would declare the array etc... I have
the
While dr.Read()
End While
part but don't know how to go about populating the array. Thanks in
advance
James
"jimmy" <ja**************@tiscali.co.ukschrieb
Hi,
Does anyone know how to read the contents of a datareader into an
array? The datareader will only hold one field called CuttingID. Can
anyone help me including how i would declare the array etc... I have
the
While dr.Read()
End While
part but don't know how to go about populating the array. Thanks in
advance
VB 2003:
Dim values As New ArrayList
Dim CuttingIDs As Integer()
Dim dr As Data.OleDb.OleDbDataReader
While dr.Read()
values.Add(dr(0))
End While
CuttingIDs = DirectCast(values.ToArray(GetType(Integer)), Integer())
VB 2005:
Dim CuttingIDs As New System.Collections.Generic.List(Of Integer)
Dim dr As Data.OleDb.OleDbDataReader
While dr.Read()
CuttingIDs.Add(dr.GetInt32(0))
End While
Armin
Thanks alot to everyone who contributed to this. Managed to fix my
problem using a mixture of these ideas and also learnt something in the
process!
Seth,
I think that you would not give your solution without telling what is
happening in that.
For the OP there is everytime build a complete new array with the Redim, it
is not just setting of some pointers. Therefore the other showed arraylist
sample is much better.
Cor
"rowe_newsgroups" <ro********@yahoo.comschreef in bericht
news:11**********************@m58g2000cwm.googlegr oups.com...
Does it have to be an Array or could you use a List <Of Whatever>? If
you use a List you just need to use it's .Add method to insert the
data.
Anyways, here's some air code for the array:
Dim str(1) as String
while dr.Read()
str(str.Length - 1) = CStr(dr.GetValue(0))
Redim str(str.Length)
end while
That should be close to what you need to do to use an array.
Thanks,
Seth Rowe
jimmy wrote:
>Hi,
Does anyone know how to read the contents of a datareader into an array? The datareader will only hold one field called CuttingID. Can anyone help me including how i would declare the array etc... I have the
While dr.Read()
End While
part but don't know how to go about populating the array. Thanks in advance
James
I think that you would not give your solution without telling what is
happening in that.
Good point Cor, next time I won't be as lazy and explain things a
little :-)
Thanks,
Seth Rowe
Cor Ligthert [MVP] wrote:
Seth,
I think that you would not give your solution without telling what is
happening in that.
For the OP there is everytime build a complete new array with the Redim, it
is not just setting of some pointers. Therefore the other showed arraylist
sample is much better.
Cor
"rowe_newsgroups" <ro********@yahoo.comschreef in bericht
news:11**********************@m58g2000cwm.googlegr oups.com...
Does it have to be an Array or could you use a List <Of Whatever>? If
you use a List you just need to use it's .Add method to insert the
data.
Anyways, here's some air code for the array:
Dim str(1) as String
while dr.Read()
str(str.Length - 1) = CStr(dr.GetValue(0))
Redim str(str.Length)
end while
That should be close to what you need to do to use an array.
Thanks,
Seth Rowe
jimmy wrote:
Hi,
Does anyone know how to read the contents of a datareader into an
array? The datareader will only hold one field called CuttingID. Can
anyone help me including how i would declare the array etc... I have
the
While dr.Read()
End While
part but don't know how to go about populating the array. Thanks in
advance
James
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: VIJAY KUMAR |
last post by:
Hi,
Problem: Return ArrayList where Values are Added using DataReader.
Note: My Data Reader returns M Columns and N Rows
I am using DataReader in Data Access layer. I want to return this...
|
by: Rob via .NET 247 |
last post by:
Ok, I'm new to .NET so I'm afraid I'm doing something stupidhere, but I'm trying to populate a DataSet manually from aDataReader, and its turning out to be ridiculously difficult.
Yes, I could use...
|
by: Nikhil Patel |
last post by:
Hi all,
I need to read rows from DataReader. The rows have two columns FieldName
and FildeValue.
Below is a small sample data:
FieldName FieldValue
Company ABC Corp.
Company ...
|
by: Filip |
last post by:
Hello all,
Is there a way to dump a DataReader into an array, or get the number of rows
so I can get my array sized.
At the moment I'm converting my DataReader into a DataTable so I can get the...
|
by: Cory Toms |
last post by:
Hey All,
I have question about the best way to go about doint this:
SqlDataReader _dr=components.getItems();
fooclass _myarray = new fooclass; //create new array of my class
int i=0;
...
|
by: I am Sam |
last post by:
I need to stuff an array with information from a database/DataReader in such
a way that the array will read the day of an event; ie,
M=13
string EventArray=new String;...
|
by: Brent |
last post by:
I'm having a hard time wrapping my head around how to build a
multi-dimensional array of n length out of a DataReader loop. Take this
pseudo-code:
=======================================
public...
|
by: jimmy |
last post by:
Hi again,
sorry for posting two questions so close together but im working on a
school project which is due in soon and running into some difficulties
implementing the database parts. I have the...
|
by: =?Utf-8?B?ZGJhMTIz?= |
last post by:
Note, I'm using C#
I am wondering what type of control I should use for iterating through the
set of records returned by callin this method below, so that I can then do
some stuff with each...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |