当从SQL (c#)加载到组合框时无法设置Datatextfield和dataValuefield
本文关键字:设置 Datatextfield dataValuefield 组合 SQL 加载 当从 | 更新日期: 2023-09-27 18:13:14
我有方法,我检索数据表,我正在尝试加载到组合框,它工作正常,但我无法设置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";
这两个属性:
drpDownProfiles.DataTextField = "Not Working";
drpDownProfiles.DataValueField = "Not Working";
应该这样设置:
drpDownProfiles.DataTextField = "CampaignName";
drpDownProfiles.DataValueField = "Id";