Click here to Skip to main content
15,889,096 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i want to display the column names based on the table names and show that table records in the gridview




please help

What I have tried:

private static string[] GetAllTableNames()
       {
           SqlConnection con = new SqlConnection(@"user id=sa;password=ssa;database=Mohan;data source=PCTH101\PCTH101");
           SqlCommand cmd = new SqlCommand("select name from sys.tables", con);
           SqlDataAdapter da = new SqlDataAdapter(cmd);
           DataTable dt = new DataTable();
           da.Fill(dt);
           return dt.AsEnumerable().Select(k => k[0] + "").ToArray();
       }
it is showing only display table names and want to display column names
Posted
Updated 8-Jun-17 0:12am
Comments
F-ES Sitecore 2-Jun-17 9:01am    
Google how to get the field names and you'll find the relevant sql for that. I posted a link this morning to a page that shows you how to do this in the thread started by someone who is probably trying to cheat the same coursework that you are

https://www.codeproject.com/Questions/1190181/How-to-get-column-names-by-passing-table-name-in-M

At least you're using a more appropriate database access technology.

1 solution

check below link

https://www.codeproject.com/Articles/13461/how-to-create-columns-dynamically-in-a-grid-view

https://www.codeproject.com/Questions/1107305/How-to-add-header-columns-in-gridview-based-on-SQL
 
Share this answer
 
v2

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