473,624 Members | 2,615 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lazy-Man's DataReader Display

Hi. I have a whole bunch of queries that I'll be running and returning in
OleDbDataReader objects. Some of these DataReaders will just be a simple
singe table result and others will be more complex with Sub-Tables and
Summaries, etc., etc. Here's my question:

Is there a way to use any of the ASP.NET 2.0 Data Controls - or any other
mechanism - to display the DataReader results without having to define all of
the columns and all that in design-time? I'm really not all that concerned
about the appearance of the output, I just want an easy way to display it
more or less the way it's displayed when you use any kind of query console
program and get results.

Any help is much appreciated.

Alex
Jul 1 '06 #1
3 1510
Hi,

GridView with AutoGenerateCol umns="True" would autogenerate the columns
based on the data, and wouldn't need much to display data in a table format.
It just cannot show relations out of the box, you could use data source
controls with filtering to work in scenarios like that.

If you purely do it in console software, you could take field count from
dataReader and always for every DataReader row, loop through the columns and
build the display manually.

Any way, on ASP.NET QuickStarts you can find lots of examples how to do it
quickly and easily:
http://www.asp.net/QuickStart/aspnet...a/default.aspx

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
"Alex Maghen" <Al********@new sgroup.nospam> wrote in message
news:EE******** *************** ***********@mic rosoft.com...
Hi. I have a whole bunch of queries that I'll be running and returning in
OleDbDataReader objects. Some of these DataReaders will just be a simple
singe table result and others will be more complex with Sub-Tables and
Summaries, etc., etc. Here's my question:

Is there a way to use any of the ASP.NET 2.0 Data Controls - or any other
mechanism - to display the DataReader results without having to define all
of
the columns and all that in design-time? I'm really not all that concerned
about the appearance of the output, I just want an easy way to display it
more or less the way it's displayed when you use any kind of query console
program and get results.

Any help is much appreciated.

Alex

Jul 1 '06 #2
Thanks Teemu for your informative inputs.

Hi Alex,

Do you think the "AutogeneratedC olumns" option is suitable for your
scenario. Based on my understanding, if you do not want to design any
column/layout for the Gridview or Table at design-time, you will need to
completely do them in code at runtime. And I suggest you consider directly
use the ASP.NET Table control and dynamically creating the tablerows and
tablecells(Tabl e control is much more flexible than gridview or other
databound based control). For example, the following code dynamically
populate a ASP.NET table control through the data reading from a DataReader:

#there is an emtpy ASP.NET Table control on the page:
=============== ===========
protected void Page_Load(objec t sender, EventArgs e)
{

PopulateTable() ;
}

protected void PopulateTable()
{
SqlConnection conn = new
SqlConnection(W ebConfiguration Manager.Connect ionStrings["LocalNorthWind "].Co
nnectionString) ;

conn.Open();
SqlCommand comm = new SqlCommand("sel ect CategoryID, CategoryName,
Description from categories", conn);

SqlDataReader reader = comm.ExecuteRea der();

int cols = reader.FieldCou nt;

TableHeaderRow thr = new TableHeaderRow( );

for (int i = 0; i < cols; i++)
{
TableHeaderCell thc = new TableHeaderCell ();
thc.Text = reader.GetName( i);

thr.Cells.Add(t hc);
}

Table1.Rows.Add (thr);
while (reader.Read())
{
TableRow tr = new TableRow();

for (int i = 0; i < cols; i++)
{
TableCell tc = new TableCell();
tc.Text = reader.GetValue (i).ToString();
tr.Cells.Add(tc );
}

Table1.Rows.Add (tr);
}
reader.Close();
conn.Close();
}
=============== =============== ===

also, if you have queried multiple results in the datareader, you can use
the DataReader.Next Result method to get the next resultset (after you've
finishing looping through the former resultset).

Hope this helps.

Regards,

Steven Cheng

Microsoft MSDN Online Support Lead
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 3 '06 #3
Hi Alex,

Does those suggestion help you some on this issue? If there is anything
else we can help, please feel free to post here.

Regards,

Steven Cheng
Microsoft MSDN Online Support Lead
=============== =============== =============== =====

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Jul 5 '06 #4

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

Similar topics

2
4034
by: Vinay Aggarwal | last post by:
I have been thinking about the lazy initialization and double checked locking problem. This problem is explain in detail here http://www.cs.umd.edu/~pugh/java/memoryModel/DoubleCheckedLocking.html I am not fully convinced that this problem cannot be solved. I am going to propose a solution here. For the sake of discussion I will post my solution here. It is possible that the proposed solution does not work, feedback and comments are...
25
2379
by: Steven Bethard | last post by:
So I end up writing code like this a fair bit: map = {} for key, value in sequence: map.setdefault(key, ).append(value) This code basically constructs a one-to-many mapping -- each value that a key occurs with is stored in the list for that key. This code's fine, and seems pretty simple, but thanks to generator
3
2317
by: Jeff Johnson [MVP: VB] | last post by:
What is the point of lazy * and lazy ? ? "Nothing" will always succeed first, right? If not, can someone give me an example of when either of these might be used?
354
15782
by: Montrose... | last post by:
After working in c# for a year, the only conclusion I can come to is that I wish I knew c. All I need is Linux, the gnu c compiler and I can do anything. Web services are just open sockets hooked up to interfaces. The Gtk is more than enough gui.
12
2806
by: Siemel Naran | last post by:
What is a good idiom for handling a lazy object? I see 2 good possibilities. Any more, any comments? Which way do people here use? (1) class Thing { public: Thing(double x, double y) : x(x), y(y), calculated(false) { } double operator()() const {
2
1303
by: joegen | last post by:
Hi, I am working on an o project that involves Lazy Parsing. To be more specific, Its a SIP Message class that implements zero copy and lazy parsing. Below is a sample function that is causing me problems. Since my object is a lazy parser, it needs to evaluate the object to be parsed during the time an accessor is called. BOOL SIPMessage::GetAuthorization( Authorization & h
4
5359
by: SL33PY | last post by:
Hi again, I've been coding in vb .Net on my most recent project and during a debug session I noticed that VB .Net hasn't got lazy evaluation... WHY?! I love lazy evaluation and actually count on it. In my current application there is data that may or may not exist depending on a certain value. It's a set of rules that may or may not apply. At a certain time in the code, there is the following (alike anyhow) statment.
9
3492
by: sturlamolden | last post by:
Python allows the binding behaviour to be defined for descriptors, using the __set__ and __get__ methods. I think it would be a major advantage if this could be generalized to any object, by allowing the assignment operator (=) to be overloaded. One particular use for this would be to implement "lazy evaluation". For example it would allow us to get rid of all the temporary arrays produced by NumPy. For example, consider the...
39
5053
by: Boltar | last post by:
Why does C do lazy evaluation for logical boolean operations but not bitwise ones? Ie: the following program prints "1 2" , not "1 1" under gcc main() { int a = 1; int b = 1; 0 && ++a;
6
3926
by: Peng Yu | last post by:
Hi, I'm wondering if the following assignment is lazy copy or not? Thanks, Peng std::vector<intv. v.push_back(1); v.push_back(2);
0
8179
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8341
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8490
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7174
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4084
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2612
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1796
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1489
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.