Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
var trer = tds.SelectNodes("//input[@type='hidden' and @name='rateid']|tr").Select(x => x).ToList();
var currentmonth = DateTime.Today.Month.ToString();
ClearTripRooms val = new ClearTripRooms();
for (var z = 0; z < trer.Count; z += 3)
{

ClearTripRate obj = new ClearTripRate();
obj.TraiffID = trer[z].Attributes[2].Value;
obj.Date = trer[z + 1].ChildNodes[1].InnerText.Trim();
obj.SingleNetRate = trer[z + 1].ChildNodes[5].ChildNodes[1].InnerText.Trim();
obj.SingleSellRate = trer[z + 1].ChildNodes[7].ChildNodes[1].InnerText.Trim();
obj.DoubleNetRate = trer[z + 2].ChildNodes[3].ChildNodes[1].InnerText.Trim();
obj.DoubleSellRate = trer[z + 2].ChildNodes[5].ChildNodes[1].InnerText.Trim();
list.Add(obj);
}
val.cleartriprate = list;
Posted
Updated 7-Oct-15 2:52am
v3
Comments
Richard MacCutchan 20-Aug-15 5:19am    
Please do not just dump your code and expect other people to fix it. Explain where the error occurs and what is the value of the variable in error. If necessary use your debugger to collect more information.
Member 10918596 20-Aug-15 5:26am    
i got error Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
Member 10918596 20-Aug-15 5:27am    
actually i extract some information from one html document.That case i got above error
Member 10918596 20-Aug-15 5:28am    
it loaded correctly bt i got error in var tds = (from td in doc.DocumentNode.Descendants("table")
select td).ToList()[2].ChildNodes[2];

this line
phil.o 7-Oct-15 8:59am    
Not a question.

We can't tell you why - because we don't have access to your data, and can't run your program under the same conditions you do as a result.

But you can look at it yourself, and find out.
Use the debugger.
First, to make it easier for you, break out that line:
C#
var tdsA = doc.DocumentNode.Descendants("table");
var tdsB = (from td in tdsA
           select td).ToList();
var tdsC = tdsB[2];
var tdsD = tdsC.ChildNodes;
var tdsE = tdsD[2];
var tds = tdsE;
Then put a break point on the first line, and run your app.
When it hits the breakpoint, hover the mouse over "doc" and make sure it's valid. If so, check the properties and make sure they aren't null either.
Step over the line, and look at tdsA = is it ok?
Keep going until you spot exactly which part is null.

Then you can start looking at why - but until you know that, you can't do anything.
 
Share this answer
 
How do you know that z+1 ans z+2 are always inferior to trer.Count ?
 
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