Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi Guy, i Need your help please.
I receive a Data of Type List<classdata> from a WebService. and insert it in a DataTable this List is Static. see the Code:
C#
        private static List<ClassData> DataList;  
       public static void DataListUpdate()
        {
                DataList = webservice.GetCommissioningClientView().ToList();
        }



        public static DataTable GetDataListTable()
        {
            try
            {

                DataTable DTable = new DataTable();
                DTable.Columns.Add("DataDesc");
                DTable.Columns.Add("DataID");

var SortDataByPriority = from table in DataList                                         
                         orderby table.highestPriority descending
                         select table;

              
                foreach (var DataObject in SortDataByPriority )
                {
                    ClassData orderData = DataObject as ClassData;
                    
                    foreach (var element in DataObject.GetDetails)
                    {
                        row = DTable.NewRow();
                        row[0] = element.MatDesc;
                        row[1] = element.EntryMaterialID;


                           
   if (DTable.Columns.Contains(DataObject.DataID)) 
 {

   if((DTable.Rows[foundRowIndex][DataObject.DataID] as DataElement) != null);
 {
    //### Hieer is my Problem ####  
      
    (DTable.Rows[foundRowIndex][DataObject.DataID] as DataElement).ElementQuantity += Element.EntryQuantity ; 
  //###

  }

  else 
   {
      DTable.Rows[foundRowIndex][DataObject.DataID] = ObjectElement;
   }
}


after verification i observe that the ObjectClass Propertie value has been changed too.
for example
DataElement.Quantity = 23 // Initial Value
after Addition
DataElement.Quantity = 46; not my Purpose.

my purpose is just to Change a value of a a Object insert a new Value in my DataTable and the OjectClass stay without Change.
like this;

##before Addition
DataElement.Quantity = 23 // Initial
##after Addition
DataElement.Quantity = 23 // Object stay intact

##DataTable
Object with a value: DataElement.Quantity = 46

but when i made a Change the Value of the Propertie it Change a value of my ObjectClass.
Please where i'm doing wrong??
Posted
Comments
Sergey Alexandrovich Kryukov 27-Sep-13 10:07am    
Why "static"? For a method, it simply means that there is no access to the instance, to "this"...
And static objects are bad, should be used only in rare cases...
—SA
stefan from germany 27-Sep-13 10:11am    
you mean it will be better to use a non Static Method?
Sergey Alexandrovich Kryukov 27-Sep-13 10:15am    
No, you need to use static when you are not accessing instance and non-static (called instance method) when you are using it.
See the difference: 1) method, 2) object.
—SA

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