Data | data sources
A dataset is often used as a data source for a control in code writing, and a control can only bind to one data source. If you want to bind the results of multiple query databases to a single control, you must populate the same data source with the results of multiple queries. Of course this feature can also be dynamically drawn to the table, but I feel that the dynamic processing table is too cumbersome. For this purpose the following tests were done and the test succeeded, now shared out.
Principle: The results of multiple queries are populated into the same table in the same dataset, but the same alias is required for the two-time fill, otherwise an unnecessary null row appears.
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, sql2 use the same field alias Yhm, ZSXM
5 using (OracleConnection connection = new OracleConnection ("Data source=abeen"; User Id=system; Password=abeen; "))
6 {
7 DataSet ds = new DataSet ();
8 Try
9 {
Ten connection. Open ();
One oracledataadapter command = new OracleDataAdapter (sql2,connection);
command. Fill (ds,0,5, "tablename");//The first time to populate the data to TableName
Command = new OracleDataAdapter (sql1,connection);
command. Fill (ds, "tablename");//second padding data to TableName
15
this. The results of the datagrid1.datasource=ds;//two-time population are in the DS tablename.
this. Datagrid1.databind ();
18}
catch (System.Data.OracleClient.OracleException ex)
20 {
throw new Exception (ex. message);
22}
23
24}
25}