Click here to Skip to main content
16,012,468 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi everybody.i have some problem please help me.
i have three cols in my database table named col1,col2,and col3. i want that when user clicks on a button the a for loop takes the values of these cols one by one and show it on the web page. can some body tell me how to do it. i m using asp.net with c#. thanks in advance.
Posted

Hope this will help..
C#
foreach(DataColumn col in ds.Tables[0].Columns)
{
  Console.WriteLine("{0} = {1}", column, column.DataType);
}


[Your question is not clear. Please Improve you questions.]
 
Share this answer
 
v2
Hi saifullahiit


step1:
take database connection and create command for selecting the values like(select * from employee--this will give all the values of employee)

step2:
use any databound contorl(gird or datalist or list view or repeter) then bind that data to that contorl

like this:

need to add namespace:
Using System.Data.Sqlclient;

SqlConnection con=new SqlConnecton("give here your connection string");
SqlCommand cmd=new SqlCommand("give your query here");
Dataset ds=cmd.ExecuteReader();
if(ds.tables.count>0)
{
if(ds.tables[0].rows.count>0)
{
grid1.Datasource=ds.tables[0];
grid1.databind();
}
}



like this you need to do,if you have any doubts,let me know

thanks
naresh.G
 
Share this answer
 
Comments
saifullahiit 26-Aug-11 2:59am    
i m doing it but i is giving error that cannot convert datareader to dataset(ds=cmd.executereader)
nareshgundapaneni 26-Aug-11 3:37am    
1.using System.Data.SqlClient;
using System.Data;


2.SqlConnection con = new SqlConnection("give here your connection string");
SqlDataAdapter da=new SqlDataAdapter("select * from employee",con);
DataSet ds=new DataSet();
da.Fill(ds);
if(ds.tables.count>0)
{
if(ds.tables[0].rows.count>0)
{
grid1.Datasource=ds.tables[0];
grid1.databind();
}
}

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