Combobox
從SQL數據庫中提取名稱列,但是選中時需要將dentist
列表中的其他屬性填充到標記爲TextBoxes
的列表中。從組合框中選擇時無法填充列表集合
在If
聲明是我得到的錯誤,突出顯示的代碼是dent.Name
。錯誤如下:
描述:無法隱式轉換類型 '字符串' 到 '廉政'
namespace DentistSurgery
{
public partial class Dentist_Info : Form
{
Surgery mySurgery = new Surgery();
public SqlCommand SelectCommand;
private SqlDataAdapter da;
DataRow dr;
Surgery _formsSurgery;
public Dentist_Info(Surgery SurgeryToDisplay)
{
_formsSurgery = SurgeryToDisplay;
}
public void FillCombo()
{
using (SqlConnection conn = new SqlConnection(@"Data Source = GGJG; Initial Catalog = DentistDB; Integrated Security = True"))
{
SqlCommand SelectCommand = new SqlCommand("SELECT * FROM DentistInfo", conn);
conn.Open();
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter(SelectCommand);
da.Fill(ds);
foreach (DataRow dr in ds.Tables[0].Rows)
{
comboBox1.Items.Add(dr["DentistName"].ToString());
}
//conn.Close();
}
}
public Dentist_Info()
{
InitializeComponent();
FillCombo();
}
public void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
List<Dentist> dentistList = new List<Dentist>();
Dentist dent = new Dentist();
if (comboBox1.SelectedIndex = dent.Name)
{
txtDName.Text = dent.Name.ToString();
txtDSurname.Text = dent.Surname;
txtDDOB.Text = dent.DOB.ToString();
txtGender.Text = dent.Gender;
txtSalary.Text = dent.Salary.ToString();
}
}
請不要張貼鏈接到您的代碼的圖片。只需像您對代碼的其餘部分所做的那樣發佈代碼即可。 – Jacobr365
對不起,我不會這樣做。 – Griff