的对象强制转换为

的对象强制转换为

本文介绍了无法将类型'System.collections.generic.Keyvaluepair'[string,string]的对象强制转换为'System.IConvertible'的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法将类型'System.collections.generic.Keyvaluepair'[string,string]的对象强制转换为'System.IConvertible'的类型



这里是我的代码:----------------------------------------------- --------------------

Unable to cast the object of Type 'System.collections.generic.Keyvaluepair'[string,string] into type of 'System.IConvertible'

here is my code:-------------------------------------------------------------------

private void LoadUniversity()
{
    try
    {
        ObjUtility = new Utility();

        cmbUniversity.DataSource = ObjUtility.BindUniversity(StaticInfo.Center_Code).ToList();
          /* error is after this line (May be in BindUniversity method ) */

        cmbUniversity.DisplayMember = "Value";
        cmbUniversity.ValueMember = "Key";
        cmbUniversity.SelectedIndex = -1;
        cmbUniversity.Text = "--Select University--";
        ObjUtility = null;
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}





//////////这里是BindUniversity的代码()方法//////////



//////////here is code of BindUniversity() method//////////

public Dictionary<string, string> BindUniversity(string CenterCode)
{
    ObjUniversityInfoModel = new UniversityInfoModel();
    ObjUniversityInfoModel.CenterCode = CenterCode;
    ObjUniversityInfoServiceClient = new UniversityInfoServiceClient();
    ObjUniversityInfoModelRecordList = new List<UniversityInfoModel>();
    ObjUniversityInfoModelRecordList = ObjUniversityInfoServiceClient.GetUniversityInfoRecordList(ObjUniversityInfoModel);

    if (ObjUniversityInfoModelRecordList[0].Message == "Success"
            && ObjUniversityInfoModelRecordList[0].Status == true)
    {
        var Result = from s in ObjUniversityInfoModelRecordList
        orderby s.UniversityID descending
        select new
        {
            s.UniversityID,
            s.UniversityName
        };
        ObjDictionary = new Dictionary<string, string>();
        foreach (var Item in Result)
        {
            string U_ID = Item.UniversityID.ToString();
            string U_Name = Item.UniversityName.ToString();
            ObjDictionary.Add(U_ID, U_Name);
        }
    }
    return ObjDictionary;
}



请帮帮我......


Help me please......

推荐答案

cmbUniversity.DataSource = ObjUtility.BindUniversity(StaticInfo.Center_Code).ToList();



然后使用Step Into(F11)函数在调试器中输入方法 BindUniversity

然后使用Step Over(F10)并逐行调试方法。



通过这样做,您很可能自己找到并纠正错误。


Then use the Step Into (F11) function in the debugger to enter the method BindUniversity.
Then use Step Over (F10) and debug the method line by line.

By doing this you can most likely find and correct the error yourself.


这篇关于无法将类型'System.collections.generic.Keyvaluepair'[string,string]的对象强制转换为'System.IConvertible'的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 01:30