results of a sql query to array

L

loga123

I am using asp.net 2.0.
I want to get the results of a sql query into an array at run-time.
Number of records returned varies each time.....so I want to declare
the dimensions of array runtime based on my record count and assign the
values from recordset to the elements of array.

any help?
 
M

Mark Rae

I am using asp.net 2.0.
I want to get the results of a sql query into an array at run-time.
Number of records returned varies each time.....so I want to declare
the dimensions of array runtime based on my record count and assign the
values from recordset to the elements of array.

any help?

A little difficult without the answers to two questions:

1) Does it *have* to be an array? The System.Collections and
System.Collections.Generic namespaces have got such rich functionality these
days that the old array object is pretty much redundant.

2) What do you intend to do with the array (or whatever) once you've got the
results of your SQL query into it?
 
G

Guest

Use the SqlCommand object's ExecuteReader and fill an arraylist of items.
Either return the arraylist or convert the types you store in it as an array
like this:

return (string[])myList.ToArray(typeof(string));
 
L

loga123

Hi... I am new to .net and do not have much knowledge about the
controls available in .net.

actually my requirement is
1) I have a SQL that would return rows like
colA colB colC colD
1 R1 1 S11
1 R1 2 S12
1 R1 3 S13
2 R2 1 S21
2 R2 2 S22
3 R3 1 S31
3 R3 2 S32
3 R3 3 S33
where colA and colC are integers and colB and colD are string type.

2) I want to build a table (like an HTML table) DYNAMICALLY as
following
1. R1
(radio button) S11
(radio button) S12
(radio button) S13
2. R2
(radio button) S21
(radio button) S22
3. R3
(radio button) S31
(radio button) S32
(radio button) S33

Number of options under each group 1, 2, 3 will differ.
Any ideas/suggestions?
 
M

Mark Rae

Hi... I am new to .net and do not have much knowledge about the
controls available in .net.

No problem with that - no-one was born knowing this stuff.

HOWEVER, do yourself a *huge* favour, step back a bit, and buy yourself a
beginner's guide to ASP.NET which contains plenty of examples of how ASP.NET
and ADO.NET interact. There simply is no benefit whatsoever in trying to
figure it out for yourself...

E.g. you have no need at all to use an array to meet your requirements
here - simply return the data from your database into a DataSet object and
bind it to a GridView control. If you don't know what I mean by that, read
the relevant chapter(s) in the beginner's guide to ASP.NET which you've just
bought...
 
M

Mark Rae

Use the SqlCommand object's ExecuteReader and fill an arraylist of items.
Either return the arraylist or convert the types you store in it as an
array
like this:

return (string[])myList.ToArray(typeof(string));

Which means you lose all of the datatype information...

The OP doesn't need to use an array - all he wants to do is display the
results of a database query on a web page...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top