本文介绍了未添加对象引用(组合框)C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i已写下面的代码将执行我的异常对象引用未添加到实例,请帮助如何通过。



我尝试过:




i have written below code where will executing i am getting exception object reference not added to instance,please help how to get through out.

What I have tried:

void CmbhospitalsSelectedIndexChanged(object sender, EventArgs e)
    {

        try
        {
            WebClient wc = new WebClient();
            wc.Headers["Content-type"] = "application/x-www-form-urlencoded";
            NameValueCollection collection = new NameValueCollection();
            collection.Add("hid","0");
            collection.Add("sno", "2");
            byte[] bret = wc.UploadValues(URLAuth, collection);
            string sret = "";
            sret = System.Text.Encoding.ASCII.GetString(bret);
            int count=0;
            string[,] hospitalslist ;

            if (sret != "")
            {
                XmlDocument readDoc = new XmlDocument();
                readDoc.LoadXml(sret);
                count = readDoc.SelectNodes("hoskeys/hkids").Count;
                hospitalslist = new string[count, 2];
                 // alternately, _doc.Load( _strFilename); to read from a file.
                XmlNodeList xhkid = readDoc.GetElementsByTagName("hkid");
                XmlNodeList xhos_key = readDoc.GetElementsByTagName("hos_key");
                for (int i= 0; i <count; i++)
                {
                    hospitalslist[i, 0] = xhkid[i].InnerText;
                    hospitalslist[i, 1] = xhos_key[i].InnerText;
                }

                for (int i = 0; i < hospitalslist.GetLength(0); i++)
                {
                    cmbhusers.Items.Add(new { Text = hospitalslist[i, 1], Key=Convert.ToInt16(hospitalslist[i, 0]) });
                }
                 cmbhusers.DisplayMember = "Text";
                 cmbhusers.ValueMember = "Key";
            }
        }
     catch (Exception e1)
    {
        MessageBox.Show(e1.Message);
    }

  }

推荐答案


这篇关于未添加对象引用(组合框)C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 21:59