Click here to Skip to main content
15,894,405 members

Operations based on IEnumerable Comparison

prabusuccess asked:

Open original thread
I have to compare the IEnumerable data from UI and the IEnumerable data from SQL Server 2008 and have to insert/update the new elements from UI to DB and delete the elements from DB based on UI data.

I am having Distribution_X_ListType table in DB as:

DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
1              2          84528          NULL         NULL
1              3          NULL           8051         NULL
1              5          NULL           NULL         319

I am having an interface in a project as follows:

C#
public interface IDistributionList : IEntity
    {
        string Name { get; set; }
        bool ActiveFlag { get; set; }
        ...........................
        ...........................
        IEnumerable<IDistributionListType> ListTypes { get; set; }
    }


The another interface is:

C#
public interface IDistributionListType
{
    int? DistributionID { get; set; }
    int ListTypeID { get; set; }
    int EmployeeNumber { get; set; }
    int DepartmentID { get; set; }
    int LocationID { get; set; }
}


In another project I am having Save function as follows:

C#
public int Save(IDistributionList distributionList)
        {
            SqlDataReader reader = null;
            int rowsaffected = 0;
            try
            {
                sqlcommand = new SqlCommand("spGetDistributionListTypeByID", con);  //spGetDistributionListTypeByID - This SP returns all the members from Distribution_X_ListType table for the given distribution ID
                sqlcommand.CommandType = CommandType.StoredProcedure;
                sqlcommand.Parameters.AddWithValue("@Distribution_ID", distributionList.ID);

                reader = sqlcommand.ExecuteReader();

                while (reader.Read())
                {
                      ????Value Should be stored in an IDistributionListType variable,say IDistributionListTypeFromDB
                }
                ????IDistributionListType from function parameter(Lets say from UI) should be compared with the above IDistributionListTypeFromDB data.
                ????Insert/Delete should be done in DB by comparing the data.
             }
         }


Let the value of IDistributionListType from UI:

DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
1              2          84528          NULL         NULL
1              5          NULL           NULL         64


Let the value of IDistributionListType from DB:

DistributionID ListTypeID EmployeeNumber DepartmentID LocationID
1              2          84528          NULL         NULL
1              3          NULL           8051         NULL
1              5          NULL           NULL         319


I need to update the DB with the data from UI. I am having two more SPs as :

spInsertUpdateDistributionListType - Insert/Update Distribution_X_ListType table  based on DistributionID and listtypeID
spDeleteDistributionListType - Delete Distribution_X_ListType table based on DistributionID and listtypeID


I don't know how to code in ???? areas. Anybody please helpout. Thanks in advance.
Tags: C#, SQL, .NET, SQL Server, Ienumerable

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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