Solved

using two data sources for one data list

Posted on 2006-06-26
4
231 Views
Last Modified: 2012-05-05
ASP.Net 2.0 and C# 2.0 only please:

I have two data sources, different tables, same structure in the output (two sets of addresses), that I want to display in one final DataList on my aspx page.

Is there an easy way to go about doing this? I've been googling for a half hour with no luck.
0
Comment
Question by:Paul Kahl
  • 3
4 Comments
 
LVL 2

Accepted Solution

by:
JocGaurav earned 500 total points
Comment Utility
0
 
LVL 3

Author Comment

by:Paul Kahl
Comment Utility
The example in the first link looks approachable, with one small question from me.

I have two stored procedures, and two calls to the database (these sprocs are used singly in some places, so they have their own datasets in my database object layer), so I have two functions in my DBLayer to call:

getPrimaryAccountAddress
getAccountAddressList

They both contain the same columns (cherry picked from larger tables with many unmatched columns). I want to just spew out both of them.

I'm a bit of a newbie to .Net (This would be my third week using it full-time), so I'm not really sure how to use those two data sources in this (the linked code you mentioned):

private void MergeDataTable()
    {
        DataTable dtOne = new DataTable("MyFirstTable");
        dtOne.Columns.Add("Number");

        DataTable dtTwo = new DataTable("MySecondTable");
        dtTwo.Columns.Add("Number");

        // Populate the first table
        for (int i = 1; i <= 10; i++)
        {
            DataRow row = dtOne.NewRow();
            row["Number"] = "Data" + i;
            dtOne.Rows.Add(row);
        }

        // Populate the second table
        for (int i = 11; i <= 20; i++)
        {
            DataRow row = dtTwo.NewRow();
            row["Number"] = "Data" + i;
            dtTwo.Rows.Add(row);
        }

        // Now merge the two tables /* ONLY ONE LINE OF CODE COOL RIGHT! */
        dtOne.Merge(dtTwo);
        GridView1.DataSource = dtOne;
        GridView1.DataBind();
    }

0
 
LVL 3

Author Comment

by:Paul Kahl
Comment Utility
Ok - I figured out how to hook up my two data sources, but I can't get it to just output the rows and colums (in this case 3 rows, 5 columns).

My code:

public void getPortalAccountAddressList(int intAxaptaCustNum)
    {
        DataTable dtOne = new DataTable();
        dtOne = AxaptaWeb.getPrimaryAccountAddress(intAxaptaCustNum);

        DataTable dtTwo = new DataTable();
        dtTwo = AxaptaWeb.getAccountAddressList(intAxaptaCustNum);

        // Populate the first table
        for (int i = 1; i <= 1; i++)
        {
            DataRow row = dtOne.NewRow();
            dtOne.Rows.Add(row);
        }

        // Populate the second table
        for (int i = 11; i <= 20; i++)
        {
            DataRow row = dtTwo.NewRow();
            dtTwo.Rows.Add(row);
        }

        // Now merge the two tables /* ONLY ONE LINE OF CODE COOL RIGHT! */
        dtOne.Merge(dtTwo);
       
        dlCPAccountAddressList.DataSource = dtOne;
        dlCPAccountAddressList.DataBind();
    }
0
 
LVL 3

Author Comment

by:Paul Kahl
Comment Utility
OK - answered my own question on that last point. The following code correctly accesses the data the way I'm wanting (played with the looping a bit on the data population). For those who want to have the first table output correctly, change "int i = 2" to "int i = 1". I set it to 2 because I know I will ALWAYS only have 1 record, so I set it up to basically not repeat the rows in the first table.

public void getPortalAccountAddressList(int intAxaptaCustNum)
    {
        DataTable dtOne = new DataTable();
        dtOne = AxaptaWeb.getPrimaryAccountAddress(intAxaptaCustNum);
        int dtOneRowCount = dtOne.Rows.Count;

        DataTable dtTwo = new DataTable();
        dtTwo = AxaptaWeb.getAccountAddressList(intAxaptaCustNum);
        int dtTwoRowCount = dtTwo.Rows.Count;

        // Populate the first table
        for (int i = 2; i <= dtOneRowCount; i++)
        {
            DataRow row = dtOne.NewRow();
            dtOne.Rows.Add(row);
        }

        // Populate the second table
        for (int i = 11; i <= dtTwoRowCount; i++)
        {
            DataRow row = dtTwo.NewRow();
            dtTwo.Rows.Add(row);
        }

        // Now merge the two tables /* ONLY ONE LINE OF CODE COOL RIGHT! */
        dtOne.Merge(dtTwo);
       
        dlCPAccountAddressList.DataSource = dtOne;
        dlCPAccountAddressList.DataBind();
    }

Thanks, JocGaurav. Your help was timely and accurate, and just what I needed.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now