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

时间:2015-09-17 14:59:15

标签: c# sql drop-down-menu combobox datatable

我有检索数据表的方法,我正在尝试加载到组合框并且它工作正常但我无法设置Datatextfield和DataValuefield,当我尝试它显示错误指示不包含定义。

这是检索数据表

的方法的代码片段
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;

加载到组合框的代码片段下面

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

1 个答案:

答案 0 :(得分:0)

这两个属性:

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

应设置为:

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