Cheap And Reliablle Hosting :: How To Merging Multiple DataTables Into Single DataTable Using ASP.Net C#

Data comes from multiple resources. Maybe sometimes it’s a similar data type but sometimes the information is different. Consider a bus reservation system with a different vendor from which similar bus seats are reserved and those are various sources. If the bus owner wants to see a single result set then we need to merge the data into a single set. Here i just giving a sample scenario, it also may be used for a different scenario.

Step-by-step how to merge multiple tables into a single table.

Step 1

Create an ASP.Net web application as in the following:
  1. “Start” – “All Programs” – “Microsoft Visual Studio”.
  2. “File” – “New Project” – “C#” – “Empty Project” (to avoid adding a master page).
  3. Provide the project a name such as “MergeMultipleDataTable” or another as you wish and specify the location.
  4. Then right-click on Solution Explorer and select “Add New Item” then select the Default.aspx page.
  5. Drag and drop three Grid Views to bind the records after joining the two tables.
Now the Default.aspx source code will be as follows:
    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Defafult.aspx.cs" Inherits="MergeMultipleDataTable.Defafult" %>  
      
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
      
    <html xmlns="http://www.w3.org/1999/xhtml">  
    <head runat="server">  
        <title></title>  
    </head>  
    <body style="background-color: Blue">  
        <h4 style="color: White">  
            Article by Vithal Wadje</h4>  
        <form id="form1" runat="server">  
        <div>  
            <h4 style="color: White">  
               DataTable First Records Before Merging  
            </h4>  
            <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">  
                <AlternatingRowStyle BackColor="White" />  
                <EditRowStyle BackColor="#7C6F57" />  
                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />  
                <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />  
                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />  
                <RowStyle BackColor="#E3EAEB" />  
                <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />  
                <SortedAscendingCellStyle BackColor="#F8FAFA" />  
                <SortedAscendingHeaderStyle BackColor="#246B61" />  
                <SortedDescendingCellStyle BackColor="#D4DFE1" />  
                <SortedDescendingHeaderStyle BackColor="#15524A" />  
            </asp:GridView>  
            <br />  
            <h4 style="color: White">  
                 DataTable second  Records Before Merging  
            </h4>  
            <asp:GridView ID="GridView2" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">  
                <AlternatingRowStyle BackColor="White" />  
                <EditRowStyle BackColor="#7C6F57" />  
                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />  
                <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />  
                <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />  
                <RowStyle BackColor="#E3EAEB" />  
                <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />  
                <SortedAscendingCellStyle BackColor="#F8FAFA" />  
                <SortedAscendingHeaderStyle BackColor="#246B61" />  
                <SortedDescendingCellStyle BackColor="#D4DFE1" />  
                <SortedDescendingHeaderStyle BackColor="#15524A" />  
            </asp:GridView>  
            <br />  
        </div>  
        <h4 style="color: White">  
             DataTable second  Records after  Merging  
        </h4>  
        <asp:GridView ID="GridView3" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None">  
            <AlternatingRowStyle BackColor="White" />  
            <EditRowStyle BackColor="#7C6F57" />  
            <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />  
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />  
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />  
            <RowStyle BackColor="#E3EAEB" />  
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />  
            <SortedAscendingCellStyle BackColor="#F8FAFA" />  
            <SortedAscendingHeaderStyle BackColor="#246B61" />  
            <SortedDescendingCellStyle BackColor="#D4DFE1" />  
            <SortedDescendingHeaderStyle BackColor="#15524A" />  
        </asp:GridView>  
        <br />  
        </form>  
    </body>  
    </html>

Step 2

Create the records for the table (you can also bind to records from the database).

Scenario

We have a different vendor from which we hire employees and they provide the employee records to our software development team using a web service and our job is to merge all the vendor records into one single data table so we can insert them into our database.
Open the Default.aspx.cs page and create a Vendor table (consider they are provided) as in the following:
DataTable dt = new DataTable();  
           DataRow dr = null;  
           dt.Columns.Add("Id", typeof(int));  
           dt.Columns[0].AutoIncrementSeed = 1;  
           dt.Columns[0].AutoIncrement = true;  
           dt.Columns.Add("Name");  
           dt.Columns.Add("Employer");  
           dr = dt.NewRow();  
           dr["Name"] = "Alexia Pamelov";  
           dr["Employer"] = "LT";  
           dt.Rows.Add(dr);  
  
           DataRow dr2 = null;  
           dr2 = dt.NewRow();  
           dr2["Name"] = "friedrich Eisenhauer";  
           dr2["Employer"] = "Microsoft";  
           dt.Rows.Add(dr2);

Now create the second vendor table (consider they are provided) as in the following:

DataTable dt2 = new DataTable();  
           DataRow dr1 = null;  
          
           dt2.Columns.Add("Id", typeof(int));  
           dt2.Columns[0].AutoIncrementSeed = 1;  
           dt2.Columns[0].AutoIncrement = true;  
           dt2.Columns.Add("Name");  
           dt2.Columns.Add("Employer");  
           dr1 = dt2.NewRow();  
           dr1["Name"] = "Anjali Punjab";  
           dr1["Employer"] = "Goverment";  
           dt2.Rows.Add(dr1);

Now we have a two tables from two different vendors, now we want to merge these two table’s records into one table, then just use the merge method of DataTable and pass the table as in the following:

  //merging first data table into second data table  
             dt2.Merge(dt);  
             dt2.AcceptChanges();
Now from the preceding example it’s clear that we can merge two tables into a single table. Now let us learn about some of the merge rules of DataTables.
  •  If the number of columns do not match the second table

When the number of columns do not match the second table then it creates blank columns for the table for the column(s) that do not match, as in the following

In the preceding you saw that the first data table only has two columns, Id and Employer, and the second table has the three columns Id, Employer and Name so the first table is created with a blank column.
  •  If the data type of a column does not match the second table

The data types must match. If the column names are the same and if the column name in both tables are the same and the data type is different then it shows the following error.

eror

From preceding image it’s clear that it must match the data type of both the columns.
  • If the column name does not match any in the second table

If a column name does not match in the second table then it creates records with a blank in each column that does not match and keeps their own orignal column names as follows.

So let us bind three Grid Views from three tables so we can understand the difference. Now the entire code of Defualt.aspx.cs will look as follows:

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using System.Web.UI;  
using System.Web.UI.WebControls;  
using System.Data;  
  
namespace MergeMultipleDataTable  
{  
    public partial class Defafult : System.Web.UI.Page  
    {  
        protected void Page_Load(object sender, EventArgs e)  
        {  
            DataTable dt = new DataTable();  
            DataRow dr = null;  
            dt.Columns.Add("Id", typeof(int));  
            dt.Columns[0].AutoIncrementSeed = 1;  
            dt.Columns[0].AutoIncrement = true;  
            dt.Columns.Add("Name");  
            dt.Columns.Add("Employer");  
            dr = dt.NewRow();  
            dr["Name"] = "Alexia Pamelov";  
            dr["Employer"] = "LT";  
            dt.Rows.Add(dr);  
  
            DataRow dr2 = null;  
            dr2 = dt.NewRow();  
            dr2["Name"] = "friedrich Eisenhauer";  
            dr2["Employer"] = "Microsoft";  
            dt.Rows.Add(dr2);  
  
            GridView1.DataSource = dt;  
            GridView1.DataBind();  
            DataTable dt2 = new DataTable();  
            DataRow dr1 = null;  
           
            dt2.Columns.Add("Id", typeof(int));  
            dt2.Columns[0].AutoIncrementSeed = 1;  
            dt2.Columns[0].AutoIncrement = true;  
            dt2.Columns.Add("Name");  
            dt2.Columns.Add("Employer");  
            dr1 = dt2.NewRow();  
            dr1["Name"] = "Anjali Punjab";  
            dr1["Employer"] = "Goverment";  
            dt2.Rows.Add(dr1);  
            GridView2.DataSource = dt2;  
            GridView2.DataBind();  
  
            //merging first data table into second data table  
           dt2.Merge(dt);  
           dt2.AcceptChanges();  
           GridView3.DataSource = dt2;  
           GridView3.DataBind();  
  
        }  
    }  
}
From the preceding example it’s clear that we can merge two tables into a single table.

Notes

  • Download the Zip file from the attachment for the full source code of the application.
  • You can also bind the tables from the database.
  • The data type of a column must be match if the column names are the same.

Summary

I hope this article is useful for all readers, if you have any suggestion then please contact me including beginners also.

Cheap And Reliable Hosting :: Cheap And Reliable ASP.NET ASPHostPortal Vs SmarterASP.NET

Find the  cheap and reliable ASP.NET Hosting company is not easy , therefore we need to compare prices, features of several hosting providers before choosing a cheap and reliable hosting.

We know that finding a cheap and reliable asp.net hosting is not an easy task and it is very important for your web application . because it is here we will compare the two hosting providers that ASPHostPortal and SmarterASP.NET , we decided to write a review about them . We will analyze the price , the features of hosting , technical support , and also the speed of the server .

How to Choose the Best Web Hosting Provider?

Without high-quality web hosting, your ability to run a successful website is going to be seriously hindered. One of the worst mistakes you can make is to choose a web hosting provider at random. If there’s a situation that calls for some thought, consideration and research, choosing a web hosting provider is it. There’s a dizzying array of web hosting providers competing for your business. How can you pinpoint the best one? Start by keeping the following points in mind.

Technical Specifications

  • The first thing you need to do when shopping for a webhost is to evaluate your disk space and bandwidth needs. If your site will feature a lot of graphics, dozens of pages and get a lot of traffic, you’re going to need decent amounts of bandwidth and disk space. Unlimited plans are available, and they make life easier. If your site is going to be simple and not generate a huge amount of traffic, you should be able to get away with smaller amounts of disk space and bandwidth.

Get a Feel for Pricing & Value

  • Some people choose web hosting providers strictly based on price. That’s not a great strategy, but you should definitely take pricing into consideration. The best providers offer options for every budget. In some cases, signing up for long subscriptions will qualify you for extra discounts.

Always Investigate Support and Customer Service

  • Even if you’re a whiz at setting up websites, it’s nice to know that help is available whenever you need it. Confirm that the web hosting provider has 24/7 support. Make sure that there are several ways to get support too. The most reliable providers provide support through email, phone and online chat.

ASPHostPortal vs SmarterASP.NET ASP.NET Hosting Features

ASPHostPortal and SmarterASP.NET include latest versions of Windows server, MSSQL, ASP.NET, ASP.NET MVC and some other advanced Microsoft technologies. To know their strength clearly, we list the main features in the following table.

[pricingtable id=’364′ ]

ASPHostPortal vs SmarterASP.NET ASP.NET Plan

ASPHostPortal offers 4 shared asp.net hosting plan named Host Intro, Host One, Host Two, and Host Three and most of clients start from their Host One plan. The prices of plans start from $1.00/month, $5.00/month, $9.00/month, and $14.00/month.

In other hand, SmarterASP.NET has 3 ASP.NET shared hosting packages named Basic, Advance, and Premium which start from $2.95/month, $4.95/month, and $7.95/month. If we compare the price, they are almost same in price and they are windows hosting provider that offer affordable ASP.NET hosting solution.

Both of them also offers money back guarantee if customers don’t satisfy with their services. ASPHostPortal guarantees 30 days money back guarantee and SmarterASP.NET has 60 days money back guarantee.

Conclusion

Both ASPHostPortal and SmarterASP.NET are great ASP.NET hosting solution. For features, they offer rich features, for pricing and money back policy, SmarterASP.NET offer advantages than ASPHostPortal. But, if you are webmasters that require high speed, than ASPHostPortal is the best option because ASPHostPortal a Microsoft Golden hosting partner has been offering well priced Windows and ASP.NET hosting plans for many years. The company also offers low priced enterprise-level hosting plans by focusing their resources on needs by ASP.NET Windows’s developers. ASPHostPortal is to offer the best web hosting value to their clients by offering products and solution in an efficient and effective way.