Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

using two data sources for one data list

Posted on 2006-06-26
4
Medium Priority
?
255 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 2000 total points
ID: 16985522
0
 
LVL 3

Author Comment

by:Paul Kahl
ID: 16985731
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
ID: 16985874
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
ID: 16985935
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

927 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