Click here to Skip to main content
15,906,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
In my application i have three datatables

c# code for three datatables

C#
//Datatable1

DataView view = wavdt.DefaultView;
view.Sort = "Wfname";
DT1 = view.ToTable();

//Datatable2

DataView view = basedt.DefaultView;
view.Sort = "Bfname";
DT2 = view.ToTable();  

//Datatable3

DataView view = templatedt.DefaultView;
view.Sort = "Tfname";
DT3 = view.ToTable();

I need to ensure that all the three datatables contain same no of rows and same filenames in all the three datatables How can i do this.I know that we can write a condition to see (dt1.rows.count == dt2.rows.count==dt3.rows.count) for rows count but how can i check for same file names in all the three datatables.My filenames will be same but extensions will be different.

If i have 123.wmv in datatable1 i will have 123.doc in second datatable and same 123 in third datatable either with doc or docx extension.If i have five rows in 1st datatable i need to ensure that my remaining datatables contain same five rows with same filenames if not then i should show error message and stop execution of my next lines of code

What I have tried:

as i am very beginner i could not find way for doing this and i could not move forward to do this
Posted
Updated 10-Sep-17 18:30pm
v2
Comments
Graeme_Grant 10-Sep-17 22:16pm    
You're a help vampire. We are not your debugging service. You need to learn to use the debugger..
Graeme_Grant 10-Sep-17 22:21pm    
Not really judging by your history. Don't be lazy, use Google Search: check datatables for duplicate data[^]
kav@94 10-Sep-17 22:31pm    
if you can help me help me out otherwise dont post the reply to my question every time when the message comes into my inbox i am checking the messages whether i have a solution but you will be replying like vampire and all which is of no use and waste of time for both of us i had posted this question as i could not get the solution if you can give me the solution i will be happy otherwise please dont reply if you cant give me the solution
Graeme_Grant 10-Sep-17 22:40pm    
I won't write your code for you but instead have given you pointers to how to do comparisons in datatables. Now you need to roll up your sleeves and write the code. It is called 'programming'.

If you are waiting for someone to write the code for you, then you have come to the wrong place. Instead, go to somewhere where other programmers will like: Hire Freelancers & Find Freelance Jobs Online - Freelancer[^]
kav@94 10-Sep-17 22:43pm    
thank you

1 solution

refer this example

DataTable dt1 = new DataTable();
           dt1.Columns.Add("ColumnName");
           dt1.Rows.Add("aa.pdf");
           dt1.Rows.Add("bb.txt");
           DataTable dt2 = new DataTable();
           dt2.Columns.Add("ColumnName");
           dt2.Rows.Add("aa.pdf");
           dt2.Rows.Add("bb.txt");
           DataTable dt3 = new DataTable();
           dt3.Columns.Add("ColumnName");
           dt3.Rows.Add("aa.pdf");
           dt3.Rows.Add("bb.txt");
           if (dt1.Rows.Count == dt2.Rows.Count && dt2.Rows.Count == dt3.Rows.Count) {
               string[] dt1Names = dt1.Rows.OfType<DataRow>().Select(row => System.IO.Path.GetFileNameWithoutExtension(row["ColumnName"].ToString()).ToLower()).ToArray();
               string[] dt2Names = dt2.Rows.OfType<DataRow>().Select(row => System.IO.Path.GetFileNameWithoutExtension(row["ColumnName"].ToString()).ToLower()).ToArray();
               string[] dt3Names = dt3.Rows.OfType<DataRow>().Select(row => System.IO.Path.GetFileNameWithoutExtension(row["ColumnName"].ToString()).ToLower()).ToArray();
               if (dt1Names.Intersect(dt2Names).Count() == dt1.Rows.Count && dt1.Rows.Count == dt2Names.Intersect(dt3Names).Count())
               {
                   // file names matching
               }
               else {
                   // not matching
               }

           }

it can be done in many ways, this is one of them
refer LINQ Except, Intersect and Union Method/ Operator in C#[^]
Path.GetFileNameWithoutExtension Method (String) (System.IO)[^]
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900