问题描述
我有49个不同的表,名称为Play_1到Play_49
所有表都有2列(number_i varchar(800),Date_(varchar 800))
其中i = 1到49
i必须在我的网格视图中调用最近4条记录的值
所以如何连接所有这些表以在一个网格视图中显示结果。按日期_。 br />
i必须加入49表。
结果应该像
Date_ Table1 Table2 ........ Table49
21/8/2016 23 55 66
20/8/2016 34 11 44
19/8/2016 12 65 22
18/8/2016 22 12 77
我的尝试:
string sqlQuery1 =从Play_1的INNER JOIN中选择顶部(4)Play_2 ON PLay_1.Number_1 = PLay_2.Number_2 ORDER BY convert(datetime,Date_,103)DESC;
SqlCommand command1 = new SqlCommand(sqlQuery1,con);
SqlDataAdapter da1 = new SqlDataAdapter(command1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
GridView1.DataSource = dt1 ;
GridView1.DataBind();
i have 49 different tables with name Play_1 to Play_49
all tables has 2 column (number_i varchar(800),Date_ (varchar 800))
where i=1to 49
i have to call values in my grid view with last 4 records
so how to join all this tables to display result in one grid view.order by Date_.
i have to join 49 table.
result should be like
Date_ Table1 Table2........Table49
21/8/2016 23 55 66
20/8/2016 34 11 44
19/8/2016 12 65 22
18/8/2016 22 12 77
What I have tried:
string sqlQuery1 = "SELECT top(4) from Play_1 s INNER JOIN Play_2 ON PLay_1.Number_1=PLay_2.Number_2 ORDER BY convert(datetime,Date_,103) DESC ";
SqlCommand command1 = new SqlCommand(sqlQuery1, con);
SqlDataAdapter da1 = new SqlDataAdapter(command1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
GridView1.DataSource = dt1;
GridView1.DataBind();
推荐答案
这篇关于如何显示从DB到gridview的不同表的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!