Introduction
In this article, we will learn how to find differences in data between two data sources along with creating a table in SQL Server and stored procedure to get the data from the table. Find more about Stored Procedure in SQL Server- Stored Procedure.
Find more about SQL Server- SQL Server
Context
One of my friends in C-sharpcorner has asked me to help display the difference between data from two data sources. One is from a SQL Server Database, and the other is from an Excel sheet. I thought it might be helpful to post this as an article rather than sending a response to his message.
Problem
The user has got two sets of data sources. One is a table in SQL Server, and another is an Excel sheet. So, we have three gridview controls on our web page. The first grid shows the data from a Database table, the second one shows the data from an Excel sheet,, and the third one should steer the difference in the data between the two grid views.
Solution
Create a table in SQL Server as below.
Enter data in the preceding table. I have entered the following data in the table.
ID |
Name |
Password |
1 |
abc |
123 |
2 |
xyz |
321 |
3 |
NNN |
789 |
4 |
PPP |
8998 |
Here is the stored procedure to get the data from the table.
Now create an Excel sheet document. It has two columns, the same as in the table above. One is "Name," and the other one is "password"; see:
Name |
Password |
abc |
123 |
xyz |
321 |
asas |
856 |
jklo |
854 |
Since we need to compare two sets of data, we need to ensure that the column names are the same so that we can compare them using the features available in C# for .NET 3.5.
Now let us build the UI for displaying the data from the two data sources and also the difference between the two data sets. My ASPX file looks as in the following.
My Code behind the file looks as in the following.
Now let us run our code and see the output.
![DtSrc1.jpg]()
You can extend or change the program with more efficient code. This article was written for first-time programmers.
Conclusion
In this article, we learned about find difference of data between two data sources.