Solved

DataSet Merge

Posted on 2013-01-23
7
238 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
[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
  • 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

738 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