我只想尝试列出通过union all联合的多个表中的前10个结果。 Allough我无法列出datareader中的前10名,有人可以帮忙吗?
下面的代码只是通过3个搜索参数将10个表合并在一起,并从' Q1'返回前1。列。
SqlCeConnection myConnectionQ1 = new SqlCeConnection("Data Source = Events.sdf");
myConnectionQ1.Open();
SqlCeCommand myCommandQ1 = myConnectionQ1.CreateCommand();
myCommandQ1.CommandText = "SELECT * FROM(SELECT * FROM(SELECT Q1, EventName, SR1SessionRaceName, LapNumber, SR1BikeSetup, Date, Track, Number, Rider FROM SR1Laptimes WHERE Q1 IS NOT NULL) as Tbl1 UNION ALL SELECT * FROM(SELECT Q1, EventName, SR2SessionRaceName, LapNumber, SR2BikeSetup, Date, Track, Number, Rider FROM SR2Laptimes WHERE Q1 IS NOT NULL) as Tbl2 UNION ALL SELECT * FROM(SELECT Q1, EventName, SR3SessionRaceName, LapNumber, SR3BikeSetup, Date, Track, Number, Rider FROM SR3Laptimes WHERE Q1 IS NOT NULL) as Tbl3 UNION ALL SELECT * FROM(SELECT Q1, EventName, SR4SessionRaceName, LapNumber, SR4BikeSetup, Date, Track, Number, Rider FROM SR4Laptimes WHERE Q1 IS NOT NULL) as Tbl4 UNION ALL SELECT * FROM(SELECT Q1, EventName, SR5SessionRaceName, LapNumber, SR5BikeSetup, Date, Track, Number, Rider FROM SR5Laptimes WHERE Q1 IS NOT NULL) as Tbl5 UNION ALL SELECT * FROM(SELECT Q1, EventName, SR6SessionRaceName, LapNumber, SR6BikeSetup, Date, Track, Number, Rider FROM SR6Laptimes WHERE Q1 IS NOT NULL) as Tbl6 UNION ALL SELECT * FROM(SELECT Q1, EventName, SR7SessionRaceName, LapNumber, SR7BikeSetup, Date, Track, Number, Rider FROM SR7Laptimes WHERE Q1 IS NOT NULL) as Tbl7 UNION ALL SELECT * FROM(SELECT Q1, EventName, SR8SessionRaceName, LapNumber, SR8BikeSetup, Date, Track, Number, Rider FROM SR8Laptimes WHERE Q1 IS NOT NULL) as Tbl8 UNION ALL SELECT * FROM(SELECT Q1, EventName, SR9SessionRaceName, LapNumber, SR9BikeSetup, Date, Track, Number, Rider FROM SR9Laptimes WHERE Q1 IS NOT NULL) as Tbl9 UNION ALL SELECT * FROM(SELECT Q1, EventName, SR10SessionRaceName, LapNumber, SR10BikeSetup, Date, Track, Number, Rider FROM SR10Laptimes WHERE Q1 IS NOT NULL) as Tbl10) as TblALL WHERE (Track = @track) AND (Number = @number) AND (Rider = @rider) ORDER BY Q1 ASC";
myCommandQ1.Parameters.AddWithValue("@track", analysisTrackComboBox.Text);
myCommandQ1.Parameters.AddWithValue("@number", analysisNumberComboBox.Text);
myCommandQ1.Parameters.AddWithValue("@rider", analysisRiderComboBox.Text);
SqlCeDataReader myDataReaderQ1;
myDataReaderQ1 = myCommandQ1.ExecuteReader();
myDataReaderQ1.Read();
daQ1tTextBox.Text = myDataReaderQ1[0].ToString();
daenq1TextBox.Text = myDataReaderQ1[1].ToString();
dasrnq1TextBox.Text = myDataReaderQ1[2].ToString();
dalnq1TextBox.Text = myDataReaderQ1[3].ToString();
dabsq1TextBox.Text = myDataReaderQ1[4].ToString();
DateTime DTout1 = Convert.ToDateTime(myDataReaderQ1[5]);
dadq1TextBox.Text = DTout1.ToString("dd/MM/yyyy");
myDataReaderQ1.Close();
myConnectionQ1.Close();