Populating data from multiple queries to the same data source

Source: Internet
Author: User
Tags bind oracleconnection
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}



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.