我试图从从数据库创建的下拉列表中选择一个名称。我似乎无法分配鬃毛。
当我单击选择按钮时,它不会将 comboBox1 中的人员姓名传递给我下一批代码。
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
using System.Data.Sql;
namespace GlidingLogsGUI2
{
public partial class InstructorSelectionForm : Form
{
List<Person> instructors = new List<Person>();
Person selectedPerson;
public InstructorSelectionForm()
{
InitializeComponent();
this.TopMost = true;
List<Person> instructors = new List<Person>();
OleDbCommand com = new OleDbCommand("SELECT * FROM Personnel WHERE [Current?] = TRUE AND [Position] = ?", Program.DB_CONNECTION);
com.Parameters.Add(new OleDbParameter("", PositionIDs.INSTRUCTOR));
OleDbDataReader dr = com.ExecuteReader();
while (dr.Read())
{
try
{
instructors.Add(new Person(dr));
}
catch
{
}
}
foreach (Person a in instructors)
comboBox1.Items.Add(a.FirstName + " " + a.Surname);
}
private void Selectbutton_Click_1(object sender, EventArgs e)
{
if (selectedPerson == null)
{
MessageBox.Show("A person must be selected first");
return;
}
new F5363(selectedPerson);
}
private void CancelButton_Click_1(object sender, EventArgs e)
{
this.Close();
}
private void InstructorSelectForm_Load(object sender, EventArgs e)
{
}
}
}