By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,714 Members | 1,363 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,714 IT Pros & Developers. It's quick & easy.

results of a sql query to array

P: n/a
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?

Jun 8 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
"loga123" <vd**********@covansys.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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?
Jun 8 '06 #2

P: n/a
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));

--
-Demetri
"loga123" wrote:
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?

Jun 8 '06 #3

P: n/a
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?


Mark Rae wrote:
"loga123" <vd**********@covansys.com> wrote in message
news:11**********************@i40g2000cwc.googlegr oups.com...
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?


Jun 8 '06 #4

P: n/a
"loga123" <vd**********@covansys.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
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...
Jun 8 '06 #5

P: n/a
If I use "gridview", how can I display radiobuttons for each group?
Mark Rae wrote:
"loga123" <vd**********@covansys.com> wrote in message
news:11**********************@j55g2000cwa.googlegr oups.com...
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...


Jun 8 '06 #6

P: n/a
"Demetri" <De*****@discussions.microsoft.com> wrote in message
news:AB**********************************@microsof t.com...
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...
Jun 9 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.