16,011,120 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View .NET questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by sivared (Top 9 by date)
sivared
29-Jul-13 0:46am
View
Yes Rohan. I used the same code.I am beginner in C#. I am not expert. But it is not working for tables more than 32 columns.
sivared
29-Jul-13 0:09am
View
public DataTable CompareTables(DataTable first, DataTable second)
{
first.TableName = "FirstTable";
second.TableName = "SecondTable";
//Create Empty Table
DataTable table = new DataTable("Difference");
try
{
//Must use a Dataset to make use of a DataRelation object
using (DataSet ds = new DataSet())
{
ds.Tables.AddRange(new DataTable[] { first.Copy(), second.Copy() });
//Get Columns for DataRelation
DataColumn[] firstcolumns = new DataColumn[ds.Tables[0].Columns.Count];
for (int i = 0; i < firstcolumns.Length; i++)
{
firstcolumns[i] = ds.Tables[0].Columns[i];
}
DataColumn[] secondcolumns = new DataColumn[ds.Tables[1].Columns.Count];
for (int i = 0; i < secondcolumns.Length; i++)
{
secondcolumns[i] = ds.Tables[1].Columns[i];
}
//Create DataRelation
DataRelation r = new DataRelation(string.Empty, firstcolumns, secondcolumns, false);
ds.Relations.Add(r);
//Create columns for return table
for (int i = 0; i < first.Columns.Count; i++)
{
table.Columns.Add(first.Columns[i].ColumnName, first.Columns[i].DataType);
}
//If First Row not in Second, Add to return table.
table.BeginLoadData();
foreach (DataRow parentrow in ds.Tables[0].Rows)
{
DataRow[] childrows = parentrow.GetChildRows(r);
if (childrows == null || childrows.Length == 0)
table.LoadDataRow(parentrow.ItemArray, true);
}
table.EndLoadData();
}
}
catch (Exception ex)
{
throw ex;
}
return table;
}
It is working for only tables with less than 32 columns only. If a table has more than 32 columns, it is not working. Please improve this solution to work for any number of columns. Thanks in advance.
sivared
29-Jul-13 0:04am
View
Thanks. But I am using the following code. Can you help me on this. If possible please provide me C# code. for looping through data tables.
public DataTable compareanotherlogic(DataTable FirstDatatable,DataTable SecondTable)
{
DataTable InsertTable = new DataTable("FinalInserts");
for (int i = 0; i < FirstDatatable.Columns.Count; i++)
{
InsertTable.Columns.Add(FirstDatatable.Columns[i].ColumnName, FirstDatatable.Columns[i].DataType);
}
var table3 = FirstDatatable.Copy();
table3.AcceptChanges();
table3.Merge(SecondTable);
var distinctRows = from row in table3.AsEnumerable()
where row.RowState != DataRowState.Modified
select row;
var distintTable = distinctRows.CopyToDataTable();
return distintTable;
}
sivared
24-Jul-13 21:39pm
View
If I have two data tables reading from xsd.Each table is same and is getting from different databases in whcih each table has 30 columns, and 28000 records. Tables differ in data in most of the columns. How can I compare the two datatables which I am reading from xsd. and create the final table with all the different records with both inserts and updates into excel sheet. Can I identify them uniquely thiat is updated record and inserted record.
sivared
24-Jul-13 21:35pm
View
Thanks. I will try this one.
sivared
24-Jul-13 12:24pm
View
We are using Oracle database. We cannot use Comparision tools. I have used Toad for the comparision.
sivared
24-Jul-13 12:20pm
View
I have same table in both two databases(one is ource and other is target). I want to compare those two tables using C# amd find out which records are inserted and which are updated.Based on that I have to generate the final CSV file or Excel file, which has to be inserted into the target database into the same table.
sivared
24-Jul-13 12:20pm
View
I have searched , but my requirement is I have same table in both two databases(one is ource and other is target). I want to compare those two tables using C# amd find out which records are inserted and which are updated.Based on that I have to generate the final CSV file or Excel file, which has to be inserted into the target database into the same table. Please provide me one good link or site for this.
sivared
24-Jul-13 12:08pm
View
I have same table in both two databases(one is ource and other is target). I want to compare those two tables using C# amd find out which records are inserted and which are updated.Based on that I have to generate the final CSV file or Excel file, which has to be inserted into the target database into the same table.
Show More