abburi chowdary

abburi chowdary

  • NA
  • 60
  • 14.1k

Index was outside the bounds of the array C#

Apr 26 2018 12:37 AM
hi,
 
In my below code while i am executing i am getting below exception please suggest where i need to update.
  1. void CmbHospitalsSelectedIndexChanged(object sender, EventArgs e)  
  2. {  
  3. try  
  4. {  
  5. WebClient wc = new WebClient();  
  6. wc.Headers["Content-type"] = "application/x-www-form-urlencoded";  
  7. NameValueCollection collection = new NameValueCollection();  
  8. collection.Add("hid","0");  
  9. collection.Add("sno""2");  
  10. byte[] bret = wc.UploadValues(URLAuth, collection);  
  11. string sret = "";  
  12. sret = System.Text.Encoding.ASCII.GetString(bret);  
  13. int count=0;  
  14. string[,] husers ;  
  15.   
  16. if (sret != "")  
  17. {  
  18. XmlDocument readDoc = new XmlDocument();  
  19. readDoc.LoadXml(sret);  
  20. count = readDoc.SelectNodes("hospitalusers/huids").Count;  
  21. husers = new string[count, 4];  
  22. // alternately, _doc.Load( _strFilename); to read from a file.  
  23. XmlNodeList xhuid = readDoc.GetElementsByTagName("huid");  
  24. XmlNodeList xuser_name = readDoc.GetElementsByTagName("user_name");  
  25. for (int i= 0; i < count; i++)  
  26. {  
  27. husers[i,0] = xhuid[i].InnerText;  
  28. husers[i, 4] = xuser_name[i].InnerText;  
  29. }  
  30.   
  31. cmbhusers.DisplayMember="text";  
  32. cmbhusers.ValueMember="key";  
  33.   
  34. for (int i = 0; i < husers.GetLength(0); i++)  
  35. {  
  36. cmbhusers.Items.Add(new { Text = husers[i, 4], Key=Convert.ToInt16(husers[i,0])});  
  37. }  
  38. }  
  39. }  
  40. catch (NullReferenceException e1)  
  41. {  
  42. MessageBox.Show(e1.Message);  
  43. }  

Answers (2)