?
Solved

using two data sources for one data list

Posted on 2006-06-26
4
Medium Priority
?
247 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

752 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