Skip to main content

How to Compare The Two data table Columns in C sharp

Q)I have one issue , my issue is
1)i want to compare the two data table columns in C sharp
2) if columns in first datatable matches with columns in second datatable
3) i want to copy those matched column data to another datatable

please help me how to do it.
By using  your code we can compare but  if the column matches with other i want to copy entire column data to another datatable .
eg;
datatable 1                                                  datatable 2
col1   col2   col3                                          col1     col2
1       test     mumbai                                       1       test
2       test     london                                         2      cool
3       test2   america                                        3       testing


i want to matched column data to another datatable
datatable 3
col1   col2
1        test
2
3


Answer)

DataTable datatable1=null; //Your Datatable1
DataTable datatable2=null; //Your Datatable2
DataTable dtMatchData = new DataTable("dtMatchData");
        dtMatchData = datatable1.Copy();
        foreach (DataColumn dt1col in datatable1.Columns)
        {
            if (datatable1.Columns.Contains(Convert.ToString(datatable2.Columns[dt1col.ColumnName])) == false)
            {
                dtMatchData.Columns.Remove(dt1col.ColumnName);

            }
        }


 

Comments

  1. I do not drop a comment, but I looked at a few of the remarks on
    "How to Compare The Two data table Columns in C sharp". I actually do
    have a few questions for you if you tend not to mind. Is it simply me or does it seem like some of these responses look
    as if they are coming from brain dead individuals? :-P And, if you are posting at additional sites, I would
    like to keep up with you. Would you post a list of all of your social sites like your Facebook page, twitter feed, or linkedin profile?


    Also visit my blog Diet Patch Review

    ReplyDelete
  2. Woah! I'm really digging the template/theme of this site. It's simple,
    yet effective. A lot of times it's challenging to get that "perfect balance" between usability and appearance. I must say you've
    done a awesome job with this. Also, the blog loads
    super quick for me on Opera. Excellent Blog!

    my webpage; Green coffee reviews

    ReplyDelete
  3. Spot on with this write-up, I actually believe that this website needs far more attention.
    I'll probably be back again to read more, thanks for the information!

    My blog post ... Max Thermo Burn Review

    ReplyDelete
  4. Very energetic blog, I liked that a lot. Will there be a part
    2?

    Also visit my web site: Automated pay days reviews

    ReplyDelete
  5. Heya i am for the first time here. I came across this board and I find It really useful &
    it helped me out a lot. I hope to give something back and help others like
    you helped me.

    Check out my website - Dermal meds facts

    ReplyDelete
  6. Thanks for another wonderful post. The place else may just anybody get that type of
    info in such a perfect approach of writing? I have a presentation
    subsequent week, and I'm on the search for such info.

    my webpage: Rvtl

    ReplyDelete
  7. Very shortly this web site will be famous amid all blogging and site-building people,
    due to it's good posts

    Feel free to surf to my web blog - Pur Essence Anti Aging

    ReplyDelete
  8. Hello There. I found your blog the usage of msn. That is an extremely well written article.
    I will be sure to bookmark it and come back to learn more of your helpful info.

    Thank you for the post. I'll certainly comeback.

    Here is my webpage ... Ultra Slim patch

    ReplyDelete
  9. Hey there! I just would like to offer you a huge thumbs up
    for the excellent info you've got here on this post. I am returning to your site for more soon.

    my page - acai ultra lean reviews

    ReplyDelete
  10. Great blog! Do you have any tips and hints for aspiring writers?
    I'm planning to start my own blog soon but I'm a little lost on
    everything. Would you recommend starting with a free platform like Wordpress or go
    for a paid option? There are so many options out there that I'm totally overwhelmed .. Any recommendations? Many thanks!

    my web-site ... green coffee reviews

    ReplyDelete
  11. Helpful information. Lucky me I found your web site unintentionally, and I am stunned why this twist of fate did not took place in advance!
    I bookmarked it.

    Also visit my blog post: Order Goji Berry

    ReplyDelete

Post a Comment

Popular posts from this blog

Tab Control in Asp.Net

Scenerio: I need your help in designing tab control in   asp.net .My requirement is I need a tab control in   asp.net (C#) like  for example goto my computer ,right click c drive and select properties.we get tabs like general,security etc....... like that i need to design one tab control(no need of any rightclick) in my web page and the database table columns should come as tabs and inseide the tab data of that particular column should come.   Example:Employee master tab1:Employee name.........his name in the tab tab2:Age.............his age tab3:Address........his address   Solution:   You can do this using a simple div <style type="text/css"> .tabs         {             position: relative;             height: 20px;             margin: 0;   ...

AI and Microsoft: Revolutionizing Efficiency in Nonprofit Organizations

  How AI and Microsoft Enhance Efficiency in Nonprofit Organizations In today’s fast-paced world, nonprofit organizations face unique challenges—limited resources, increasing demands, and the constant need to do more with less. But what if technology could be the game-changer they need? In my latest research paper,  "How AI and Microsoft Enhance Efficiency in Nonprofit Organizations" , I explore how cutting-edge technologies like Artificial Intelligence (AI) and Microsoft’s innovative tools are revolutionizing the way nonprofits operate. From streamlining administrative tasks to enhancing donor engagement and optimizing resource allocation, AI and Microsoft’s solutions are empowering nonprofits to focus on what truly matters—their mission. This paper dives deep into real-world examples, practical applications, and the transformative potential of these technologies. Whether you’re a nonprofit professional, a tech enthusiast, or simply curious about the intersection of technolo...

Social tagging overview in Sharepoint 2010

A tag is a word or phrase that identifies an individual piece of information according to a set of attributes or criteria. Tags make it easy to find and share information about a specific subject or task. Social tagging helps users categorize information in ways that are meaningful to them. Social tagging can improve the quality of search results by filtering against specific tags, and it can also connect individuals who want to share information with other users who have like interests. This article describes the social tagging features in Microsoft SharePoint Server 2010. This article does not describe how to configure social tagging features. It also does not discuss how to implement social tagging features as part of an overall social media strategy for an enterprise. About using social tagging features Social tagging features help users to share information and to retrieve relevant, high-quality content more efficiently. Such sharing encourages collaboration and b...