无法将类型'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'

查看:424
本文介绍了无法将类型'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......

推荐答案

如果你检查一下你得到的异常的堆栈跟踪将精确定位发生错误的确切行。



你也可以在这一行设置一个断点:

If you check the stack trace of the exception you get it will pinpoint the exact row where the error occurred.

You could also set a breakpoint on this line:
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'的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆