Solved

DataSet Merge

Posted on 2013-01-23
7
235 Views
Last Modified: 2013-02-12
Hello:

I used the merge function to merge two datasets together. However when they are displayed on the GridView they are shown on two different lines.

I attached an excel spreadsheet that shows the output.
Book1.xls
0
Comment
Question by:RecipeDan
  • 3
  • 3
7 Comments
 
LVL 19

Expert Comment

by:Amandeep Singh Bhullar
ID: 38810822
Try converting into datatables and then merge them
0
 
LVL 1

Author Comment

by:RecipeDan
ID: 38811443
Same thing happens.....
0
 
LVL 35

Expert Comment

by:YZlat
ID: 38811726
Can I see your code for merging?
0
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
ID: 38811755
you could convert both datasets to datatables and then do something like that:
 
for(int i=0;i<dt2.Rows.Count;i++)
{
    DataRow dr=dt1.NewRow();
    dr[0]=dt2.Rows[i][0];
    dr[1]=dt2.Rows[i][1];
    dr[2]=dt2.Rows[i][2];
    dt1.Rows.Add(dr);
}

Open in new window

0
 
LVL 1

Author Comment

by:RecipeDan
ID: 38812155
Here is the syntex that I am using. I did not create the database nor schema. I am trying to do the best with what was given to me

        SqlConnection conn;
        DataTable datatable = new DataTable();
        SqlDataAdapter adapter;
        string connectionString = "Data Source=LVAnimal;Initial Catalog=Data;User Id=AnimalUser;Password=AnimalUser;";
        conn = new SqlConnection(connectionString);
        adapter = new SqlDataAdapter("Select DIvisionA, Count(NoGames) AS Games, Teams FROM Data", conn);
        adapter.Fill(datatable);

        SqlConnection conn1;
        DataTable datatable1 = new DataTable();
        SqlDataAdapter adapter1;
        string connectionString1 = "Data Source=LVAnimal;Initial Catalog=Data;User Id=AnimalUser;Password=AnimalUser;";
        conn1 = new SqlConnection(connectionString1);
        adapter1 = new SqlDataAdapter("Select DIvisionB, Count(NoGames) AS Games, NightGames FROM Data", conn1);
        adapter1.Fill(datatable1);
        datatable.Merge(datatable1);
        GridView1.DataSource = datatable;
        GridView1.DataBind();

Open in new window

0
 
LVL 35

Expert Comment

by:YZlat
ID: 38814367
so, did you try using

 
for(int i=0;i<datatable1.Rows.Count;i++)
{
    DataRow dr=datatable.NewRow();
    dr[0]=datatable1.Rows[i][0];
    dr[1]=datatable1.Rows[i][1];
    dr[2]=datatable1.Rows[i][2];
    datatable.Rows.Add(dr);
}

Open in new window

0
 
LVL 1

Author Comment

by:RecipeDan
ID: 38820600
Yes I did. It shows three rows of duplicate data from the first datatable
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Gridview selected row 9 45
Javascript to set controls visibility 5 34
Where did System.Data.Objects go? 2 27
tableview is not updating 1 8
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

770 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