Solved

DataSet Merge

Posted on 2013-01-23
7
236 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

840 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