Click here to Skip to main content
15,884,177 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Team,
I have the code which is working.In my code there are if condition is available ,I want to implement one more If condition in exiting if condition.My Condition is as follows:

I am reading the values from excel sheet .In excel there are number of rows and columns.I have CellId,route ,place,mobilenumber ..and so on as a column name in my excel file.
for example: In Cellid column, value are 123 ,other columns are having some value related to particular record for one row
for second row,In CellID column,value are 123 but other column are null.So in this senario,I want to check the record if same number of cellid exsist then read the record in which value are present in columns not to read the value in which cellid is present but other columns are null. How can i implement this in if condition.Please guide me.

C#
public IEntityCollectionBase GetZteBbhRecords(IEntityBase xmlConfiguration)
{
   IDataReader dataReader = null;
   ExcelDataAccess excelDataAccess = null;
   IEntityCollectionBase zteBbhRecords = Kaizen2GEntityCreator.GetZteBbhEntityCollection();
   try
   {
      IXmlConfiguration xmlConfig = xmlConfiguration as IXmlConfiguration;
      Logger.Write("Inside ZteBbhDataManager.GetZteBbhRecords()", xmlConfig.LogTypeInfo);
      excelDataAccess = CommonDataManager.GetDataAccess(xmlConfig);
      dataReader = excelDataAccess.ExecuteReader();
      IZteBbh zteBbhEntity = null;
      while (dataReader.Read())
      {
         zteBbhEntity = Kaizen2GEntityCreator.GetZteBbhEntity();
         zteBbhEntity = CommonDataManager.GetEntityFromExcelRow(dataReader, xmlConfig, zteBbhEntity) as IZteBbh;
         if (zteBbhEntity != null)
         {
            if ((zteBbhEntity.CombinedMaster as ICombinedMaster).CellId > 0)
            {
               if ((zteBbhEntity.CombinedMaster as ICombinedMaster).Circle.Trim().ToUpper() == "ROTN")
               {
                  (zteBbhEntity.CombinedMaster as ICombinedMaster).Circle = "ROTN-ZTE";
               }
               else if ((zteBbhEntity.CombinedMaster as ICombinedMaster).Circle.Trim().ToUpper() == "AP")
               {
                  (zteBbhEntity.CombinedMaster as ICombinedMaster).Circle = "AP-ZTE";
               }
 
               zteBbhEntity.FileLogId = xmlConfig.FileLogId;
               zteBbhEntity.HandOverSuccessRate = zteBbhEntity.HandOverSuccessRate * 100;
               zteBbhEntity.HandOverFailureRate = zteBbhEntity.HandOverFailureRate * 100;
               zteBbhEntity.RandomAccessSuccessRate = zteBbhEntity.RandomAccessSuccessRate * 100;
               zteBbhEntity.TbfSuccessRateUl = zteBbhEntity.TbfSuccessRateUl * 100;
               zteBbhEntity.TbfSuccessRateDl = zteBbhEntity.TbfSuccessRateDl * 100;
               zteBbhRecords.Add(zteBbhEntity);
            }
         }
      }
 
      Logger.Write("Exiting ZteBbhDataManager.GetZteBbhRecords()", xmlConfig.LogTypeInfo);
   }
   catch (Exception exception)
   {
      throw exception;
   }
   finally
   {
      dataReader.CloseDataReader();
      excelDataAccess.CloseConnection();
   }
 
   return zteBbhRecords;
}


indenting reduced
Posted
Updated 15-May-14 10:42am
v3
Comments
R Harshal 15-May-14 5:03am    
Is anyone can help me.

Thanks
Harshal
R Harshal 15-May-14 5:21am    
In Simple words if i have two records with same CellId then i want to read only the cellID which contains value in other columns as there are number of columns
with cellID,if value is not present in other column then neglect that record.how to implement this in if condition.
Thanks
Harshal
R Harshal 15-May-14 6:33am    
In other words,if we found the two record with same cellID then read the cellid record in which other
columns are not null,dont consider the record in which other columns are null.
as simple as that.this I want to implement in my IF Condition.Please anyone can guide me.
very thanks
Harshal
R Harshal 15-May-14 6:58am    
i will make it more easier to understand<br><br>
it has 5 columns say (CellID, A1, A2, B1, B2) If CellID is 1 ,then i want to read the value for CellId<br>
in which other columns are not null. Secondily,no 2 rows will have same CellID but no value in other columns.In this senario,I want to read the value in which<br><br><br>
other column values are not null , even though cellId are same ,Ignore the cellid in which other columns are null .<br><br><br>
this what i want to perform in If condition.I hope everyone can understand what i Required.<br>
CellID| A1 | A2 | B1 | B2 |<br>
--------------------------<br>
1 | 123 | XY | | | <br>
1 | | | | |<br>

In first Row, CellID = 1,A1 = 123,A2 = XY
In Second Row,CellID = 1,A1 = null,A2 = null
Thanks<br>
Harshal
Matt T Heffron 15-May-14 17:02pm    
What if the two rows were in the other order?
How do you expect to know when you read the first CellID==1 row that another row exists that has non-null values, and so this shouldn't be processed, but the other one should?
What if you have two rows with the same CellID but one row has values for A1, A2 with B1, B2 null AND the other row has A1,A2 null and B1, B2 with values?
It seems that the only thing you can do is, for each CellID found, keep a copy of the associated row and then if another row with the same CellID is found, then compare the presence/absence of values and keep the "correct" one. Finally, at the end, then process the "kept" rows.

I'd suggest to use ADO.NET (OLEDB), which enables to use SQL queries to insert, update and delete Excel data. Have a look here: Accessing Microsoft Office Data from .NET Applications[^].
 
Share this answer
 
Maybe it is worth that you first get some knowledge about such simple boolean logics!
Sorry for that.....Downvotes expected!
Regards, Bruno
 
Share this answer
 
Comments
Maciej Los 16-May-14 1:40am    
Downvotes? No! +5!
[no name] 16-May-14 4:13am    
Thank you Maciej. Rgeards, Bruno

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