?
Solved

DataSet Merge

Posted on 2013-01-23
7
Medium Priority
?
241 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 35

Accepted Solution

by:
YZlat earned 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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 …
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

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