Extract New Members from Gridview

  • Hello Boss,
    kindly assist with a code to extract new members in the scenario described below:
    1. i have a table in sql that stores names and IDs,
    2. in c# datagridview "A", i upload from excel list of names and ID's and this upload can contain new names and id's not in the sql table as well as those that already exist in the sql table i have created,
    3.please can you assist with a code to differentiate in another datagridview "B" what the new members are? 

    Thnaks

  • This is so much a SQL question, but more C#, so I'm not sure how much of a useful response you'll get here (as a SQL Server forum).

    If, however, you could entertain using SQL Server to do the task though:
    I'd suggest importing the Excel Document to your SQL Server. This is "easily" achieved by using SSIS  (I say easily as the ACE drivers used for interacting with Excel can be quirky at the best of times and I don't know what your data looks like). Then, in SQL you can compare the 2 tables by using an EXIST statement.

    Without knowing anything about your data, this is a sample, but in very simple terms your query might look something like:
    SELECT *
    FROM [YourImportedTable] YIT
    WHERE NOT EXISTS (SELECT *
                      FROM [YourSourcerTable] YST
                      WHERE YST.Id = YIT.Id);

    This would return all the records in the data you imported (from Excel), where the ID does not exist in your original Source Table.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

  • Thom A - Thursday, August 17, 2017 5:36 AM

    This is so much a SQL question, but more C#, so I'm not sure how much of a useful response you'll get here (as a SQL Server forum).

    If, however, you could entertain using SQL Server to do the task though:
    I'd suggest importing the Excel Document to your SQL Server. This is "easily" achieved by using SSIS  (I say easily as the ACE drivers used for interacting with Excel can be quirky at the best of times and I don't know what your data looks like). Then, in SQL you can compare the 2 tables by using an EXIST statement.

    Without knowing anything about your data, this is a sample, but in very simple terms your query might look something like:
    SELECT *
    FROM [YourImportedTable] YIT
    WHERE NOT EXISTS (SELECT *
                      FROM [YourSourcerTable] YST
                      WHERE YST.Id = YIT.Id);

    This would return all the records in the data you imported (from Excel), where the ID does not exist in your original Source Table.

    Thanks Chief, i just tried it didnt work, i want to try and explain properly,
    in sql i have a table called PFMembers that keeps members of a provident fund and their ids
    say the next month i am supplied a list that contains same list of members (in my PFMembers) plus additional new members which are not registered in my PFMember table , (due to size of the list i may not know these new names)
    in c#, i have two gridviews, one will display the upload from excel which will contain both members registered in my PFMember and the new additional members, my question is i want to display in the 2nd gridview those new additional members. (this new members are no where in an sql table but just displayed in a gridview)

  • respuzy - Thursday, August 17, 2017 6:05 AM

    Thanks Chief, i just tried it didnt work, i want to try and explain properly,
    in sql i have a table called PFMembers that keeps members of a provident fund and their ids
    say the next month i am supplied a list that contains same list of members (in my PFMembers) plus additional new members which are not registered in my PFMember table , (due to size of the list i may not know these new names)
    in c#, i have two gridviews, one will display the upload from excel which will contain both members registered in my PFMember and the new additional members, my question is i want to display in the 2nd gridview those new additional members. (this new members are no where in an sql table but just displayed in a gridview)

    "Didn't work" doesn't tell me a lot. What did you "try"? What were the errors you received? Was it at the SSIS import stage, when comparing your results, or at a different point? All I posted was an idea on what you could do, it wasn't a solution as we don't have nearly enough information about your set up.

    Thom~

    Excuse my typos and sometimes awful grammar. My fingers work faster than my brain does.
    Larnu.uk

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply