Click here to Skip to main content
16,010,553 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am reading a excel file with 3 excel sheets and checking the rows of excel sheet for message Id

If the message Id is same in the 3 excel rows I am saving them into list string

I am using the following code doing it

C#
List<string> commonMsgIdThreeBuses = new List<string>();
                if (lstDS.Count == 3)
                {

                   
                    List<string> timeStamp = new List<string>();
                    

                    foreach (DataRow row in lstDS[2].Tables[0].Rows)
                    {


                        string fieldFromDB = row[1].ToString();
                        string FromDB = row[2].ToString();

                        foreach (DataRow row1 in lstDS[0].Tables[0].Rows)
                        {
                            string fieldFromDB1 = row1[1].ToString();

                            if (fieldFromDB == fieldFromDB1)
                            {

                                foreach (DataRow row2 in lstDS[1].Tables[0].Rows)
                                {
                                    string fieldFromDB2 = row2[1].ToString();

                                    if (fieldFromDB == fieldFromDB2)
                                    {
                                       

                                        commonMsgIdThreeBuses.Add(fieldFromDB);
                                         
                                    }



                                }
                            }
                        }
                    }
                    }
            

                foreach (Object item in commonMsgIdThreeBuses)
                {
                    Console.WriteLine(commonMsgIdThreeBuses);
                    

                }
                Console.ReadKey();


The problem is that I cannot see the message Ids on console

Can anyone help me in solving this


Thanks
John
Posted
Comments
Richard MacCutchan 23-Dec-13 5:26am    
Maybe there is no data to display. Use your debugger to step through the code and see the actual data being processed.

Well on 1st read i noticed that in foreach u print whole list ?

C#
foreach (Object item in commonMsgIdThreeBuses)
                {
                    Console.WriteLine(item);
                }


Maybe that is problem if u load data in list correctly.
 
Share this answer
 
There are far, far too many possible reasons why you don't see your message: and without your actual data we really can't even begin to guess which one it might be.

So, it's up to you!
The first thing to do is get information on exactly what is happening. So put a breakpoint on the first line in the above code, and run your app in the debugger:
C#
List<string> commonMsgIdThreeBuses = new List<string>();</string></string>
When execution reaches that line, the debugger will stop before it executes it, and let you see what is going on.
Single step through your program (which means to execute it a line at a time - there is a button on the toolbar for that) working out what should happen as a result before you do. Did what you expected happen? If so, move to the next. If not, why not?
Note that you can find out what a variable contains by hovering the mouse over it. As well as via the Auto, Local and Watch panes.

When you know what exactly it is doing, you can start thinking about why - and then you can start looking for the problem. But we can't do that for you!
 
Share this answer
 
if commonMsgIdThreeBuses is filled properly then the following code should work.

C#
foreach (Object item in commonMsgIdThreeBuses)
                {
                    Console.WriteLine(item);
                }
 
Share this answer
 
HI use the object item instead of collection..

C#
foreach (Object item in commonMsgIdThreeBuses)
                {
                    Console.WriteLine(commonMsgIdThreeBuses item);


                }
 
Share this answer
 

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