Solved

DataSet Merge

Posted on 2013-01-23
7
228 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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

14 Experts available now in Live!

Get 1:1 Help Now