如何通过在ASP.NET中传递表名来获取列名,并在gridview中显示该记录 [英] How to get the column names by passing the table name in ASP.NET and display that records in gridview
本文介绍了如何通过在ASP.NET中传递表名来获取列名,并在gridview中显示该记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想根据表名显示列名,并在gridview中显示表记录
请帮助
我的尝试:
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
推荐答案
检查以下链接< br $> b $ b
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
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
这篇关于如何通过在ASP.NET中传递表名来获取列名,并在gridview中显示该记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文