Fill data queried multiple times to the same data source

Source: Internet
Author: User
Tags oracleconnection
Fill in the Data queried multiple times to the same data source in Code Dataset is often used as the control data source during writing. Generally, a control can only be bound to one data source. If you want to bind the results of multiple queries to a control, you must fill in the results of multiple queries to the same data source. Of course, this function can also be implemented by dynamically drawing tables, but I feel it is too troublesome to dynamically Process Tables. For this purpose, the following tests were conducted and the test was successful.
Principle: Fill in the results of multiple queries to the same table of the same dataset. However, when filling the results twice, the field must be as the same alias, otherwise, there will be unnecessary null rows.
The Code is as follows: 1 Private   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 alias 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 " ); // The first time data is filled in to tablename
13 Command =   New Oracledataadapter (sql1, connection );
14 Command. Fill (DS, " Tablename " ); // The second data filling to tablename
15
16 This . Datagrid1.datasource = DS; // The results of both filling are in the tablename of DS.
17 This . Datagrid1.databind ();
18 }
19 Catch (System. Data. oracleclient. oracleexception ex)
20 {
21Throw NewException (ex. Message );
22}
23
24 }
25 }

The methods provided by garden friends are as follows:

1. Sea Wide Sky: If it is the same data source, union can be used to merge data into a data set at the database end. Of course, the column names must be the same.
2. If two dataset ds1 and DS2 with the same column name are already bound to a grid, how can this problem be solved?
Echo rod reply:
Dataset ds1 = new dataset ();
Dataset ds2 = new dataset ();
Ds1.merge (DS2 );

Life is not fair, get used to it!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.