Populate data from multiple queries into the same data source
Author:Eve Cole
Update Time:2009-07-01 16:14:59
DataSet is often used as the data source of the control in code writing. Usually a control can only be bound to one data source. If you want to bind the results of multiple queries to the database to a control, you must fill the results of multiple queries into the same data source. Of course, this function can also be implemented by dynamically drawing tables, but I feel that dynamic processing of tables is too troublesome. The following test was done for this purpose and the test was successful. I will share it now.
Principle: Fill the results of multiple queries into the same Table of the same DataSet, but when filling twice, the fields must be as the same alias, otherwise unnecessary NULL rows will appear.
The code is as follows:
1private void databing()
2 {
3 string sql1="select xqid as yhm ,xqmc as zsxm from xt_xq";//
4 string sql2="select xt_zdb_style as yhm, description as zsxm from xt_zdb";//sql1 and sql2 use the same field aliases yhm and zsxm
5 using (OracleConnection connection = new OracleConnection("Data Source=abeen;User Id=system;Password=abeen;"))
6 {
7 DataSet ds = new DataSet();
8 try
9 {
10 connection.Open();
11 OracleDataAdapter command = new OracleDataAdapter(sql2,connection);
12 command.Fill(ds,0,5,"TableName");//Fill data into TableName for the first time
13 command = new OracleDataAdapter(sql1,connection);
14 command.Fill(ds,"TableName");//Fill data into TableName for the second time
15
16 this.DataGrid1.DataSource=ds;//The results of the two fillings are in the TableName of ds
17 this.DataGrid1.DataBind();
18}
19 catch(System.Data.OracleClient.OracleException ex)
20 {
21 throw new Exception(ex.Message);
twenty two }
twenty three
twenty four }
25}
http://www.cnblogs.com/abeen/archive/2006/11/21/567893.html