我正在使用 asp.net C# SQL 创建一个网页。我需要列出一个 courseID 让用户选择,但它在下拉列表 S1111 S2222 S3333 S1111 S2222 S3333 中列出了两个相同的值,有人帮忙
protected void Page_Load(object sender, EventArgs e)
{
SqlConnection conn;
SqlDataReader dtr;
SqlCommand cmd;
string Connnection = ConfigurationManager.ConnectionStrings["ELearing"].ConnectionString;
conn = new SqlConnection(Connnection);
if (!Page.IsPostBack)
{
//Get Staff Information
conn.Open();
string cmdString = "SELECT DISTINCT CourseID FROM Schedule WHERE(StaffID = @scheduleStaffID)";
cmd = new SqlCommand(cmdString, conn);
cmd.Parameters.AddWithValue("@scheduleStaffID", Session["UserID"].ToString());
dtr = cmd.ExecuteReader();
while (dtr.Read())
{
ddlCourse.Items.Add(dtr["CourseID"].ToString());
}
dtr.Close();
conn.Close();
}
}