Solved

using two data sources for one data list

Posted on 2006-06-26
4
232 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Editing XSL files, 2 42
What .NET website keeps me current? 9 56
Cannot upload files above 1mb IIS7 11 39
Receiving a string from a WebService Push 21 36
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

911 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

21 Experts available now in Live!

Get 1:1 Help Now