abburi chowdary

abburi chowdary

  • NA
  • 60
  • 15k

Object reference not set toan instance of anobject. C#combob

Apr 25 2018 4:39 AM
hi
 
i have written below code to get values in combobox nut i am getting error as object reference not set .please suggest
  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[,] hospitalslist ;  
  15.   
  16. if (sret != "")  
  17. {  
  18. XmlDocument readDoc = new XmlDocument();  
  19. readDoc.LoadXml(sret);  
  20. count = readDoc.SelectNodes("hoskeys/hkids").Count;  
  21. hospitalslist = new string[count, 2];  
  22. // alternately, _doc.Load( _strFilename); to read from a file.  
  23. XmlNodeList xhkid = readDoc.GetElementsByTagName("hkid");  
  24. XmlNodeList xhos_key = readDoc.GetElementsByTagName("hos_key");  
  25. for (int i= 0; i <count; i++)  
  26. {  
  27. hospitalslist[i, 0] = xhkid[i].InnerText;  
  28. hospitalslist[i, 1] = xhos_key[i].InnerText;  
  29. }  
  30. for (int i = 0; i < hospitalslist.GetLength(0); i++)  
  31. {  
  32. cmbhusers.Items.Add(new { Text = hospitalslist[i, 1], Key=Convert.ToInt16(hospitalslist[i, 0]) });  
  33. }  
  34. cmbhusers.DisplayMember = "Text";  
  35. cmbhusers.ValueMember = "Key";  
  36. }  
  37. }  
  38. catch (Exception e1)  
  39. {  
  40. MessageBox.Show(e1.Message);  
  41. }  
  42. }  

Answers (2)