Click here to Skip to main content
15,920,111 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
See more:
I want to display data from database in different places. I am using datareader to read the data and stored data like this:
string name=dr["name"].ToString();

then i display the data in webpage writing code like this <=%name%> in source page.
There is a problem that if i need 100 columns of data then i need to use 100 variables to declare and store the data.

so please any one can tell me any other simple procedure to do that.

Thanks in advance


can we access datareader value in source code?
if can then how?
Posted
Updated 2-Jun-11 2:05am
v3
Comments
rudrik8 2-Jun-11 7:17am    
u can use string array.

you can use

XML
<![CDATA[<%= dr["name"].ToString() %>]]>
 
Share this answer
 
Comments
rahul dev123 2-Jun-11 8:03am    
where to use this code?
hi,

if your having different fields you have to use different variables.
or if you have same variables repeating for a number of set the you can use repeater control.
 
Share this answer
 
Any reason why you wouldn't want to use a Grid View[^] or one of the other data binding controls?

Instead of using a DataReader, populate a DataSet or DataTable then simply bind to the grid.

You can have the grid autopopulate the columns, so no need for variables or anything like that

E.g. something like this

http://aspalliance.com/757_Code_Snip_Populating_GridView_Control_Using_ASPNET_and_C_with_MouseOver_Effect.2[^]
 
Share this answer
 
use stringBuilder class to build dynamic design
stringbuilder.append("");
 
Share this answer
 
hi,

Design server side with string builder like
stBuilder.Append("...")Then u will not have to use extra variable.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900