简体   繁体   English

从SQL(C#)加载到ComboBox时无法设置Datatextfield和dataValuefield

[英]Unable To Set Datatextfield and dataValuefield When Loading To ComboBox From SQL (C#)

I have method where I retrieve datatable and I am trying load to combobox and it works fine but I am unable set Datatextfield and DataValuefield when I try to it shows error indicating does not contain defintion. 我有检索数据表的方法,并且尝试加载到组合框,它可以正常工作,但是当我尝试显示错误指示不包含定义时,我无法设置Datatextfield和DataValuefield。

here is code snippet of method to retrieve datatable 这是检索数据表的方法的代码片段

DataTable dtTable = new DataTable();
            using (SqlConnection sqlConnection = new SqlConnection(cs))
            {
                using (SqlCommand sqlCommand = new SqlCommand("SELECT Id,CampaignName FROM CampaignsTable", sqlConnection))
                {
                    sqlConnection.Open();

                    using (SqlDataReader sqlDataReader = sqlCommand.ExecuteReader())
                    {
                        dtTable.Load(sqlDataReader);
                        sqlDataReader.Close();
                    }
                }
            }

            return dtTable;

Below Code Snippet on Loading to combobox 加载到组合框时的以下代码段

drpDownProfiles.DataSource = rank.RetrieveProjectNames();
drpDownProfiles.DataTextField = "Not Working";
drpDownProfiles.DataValueField = "Not Working";

These two properties: 这两个属性:

drpDownProfiles.DataTextField = "Not Working";
drpDownProfiles.DataValueField = "Not Working";

should be set up like: 应该设置为:

drpDownProfiles.DataTextField = "CampaignName";
drpDownProfiles.DataValueField = "Id";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM