Hi Karl, thanks for the reply. I'm fairly new to .NET in general, so it's
likely there is a better way! Basically I have a database containing info
about lots of different images, including the filename. The images are
viewed one at a time, on a page with 'Next' and 'Previous' buttons.
Obviously, the 'Next' button takes you to the next image in the database.
However, file names are numeric but not sequential so the current file name
has no relation to whatever comes next! So if I'm viewing an image with
filename 00003, I have no idea what the next one is.
Basically what I need is a way to return a set of results from access, and
say 'Get the SECOND row this time' or 'Get the THIRD row this time'. I don't
know any way of doing this. I thought that by dumping them in an array, I
would be able to reference the values in the array in a more structured
fashion because I know they are sequential starting from 0.
One alternative is to modify my SQL to get the top record where the filename
is greater than the one currently being viewed (if 'Next' button clicked) or
less than the one currently being viewed (if 'Previous' button clicked). I
realised this after my original post and it's now looking favourite! But I
thought another advantage of the array method might be that once I've
queried the database once to get all the info, I can maintain it through
page postbacks rather than querying the database for one record each time
the page is loaded. What are your views on this? Would the overheads of
maintaining a large two-dimensional array be greater than querying the
database each time the page loads?
Thank you very much,
Haydn
"Karl" <none> wrote in message news:
[email protected]...
Haydn,
I'd love to know why you want to do this there is likely a better
alternative for whatever it is you are trying to do.
The only way I know how to do what you want to do is to manually loop
through your datasource:
DataTable dt = new DataTable();
dt.Columns.Add("column1");
dt.Columns.Add("column2");
dt.Columns.Add("column3");
for (int i = 0; i < 5; i++){
DataRow dr = dt.NewRow();
dr[0] = 1 * (i + 1);
dr[1] = 3 * (i + 1);
dr[2] = 2 * (i + 1);
dt.Rows.Add(dr);
}
int[,] array = new int[dt.Columns.Count,dt.Rows.Count];
for (int i = 0; i < dt.Rows.Count; i++){
for (int j = 0; j < dt.Columns.Count; j++){
array[j,i] = Convert.ToInt32(dt.Rows
[j]);
}
}
Karl
Haydnw said:
Hi,
I'd like to put a load of database results (several rows for 5 fields) into
a two-dimensional array. Now, this may be a really stupid question,
but
can
someone give me a pointer for how to do it? I can bind data to
datagrids
and
lists and stuff all day long, but can't seem to grasp this one. Any pointers
to a useful article / demo (or just any useful pointers!) would be much
appreciated.
Thanks,
Haydn