當我加載我的應用程序需要從表gebruik
C#不能得到來自數據庫表中的數據在組合框中
與行loginnaam
填補組合框cbkeuze
我得到的錯誤是:無法更改項目,因爲財產數據源已設置。
這裏是我的代碼:
private void Form1_Load(object sender, EventArgs e)
{
// SQL Connectie opzetten
SqlConnection Conn = new SqlConnection();
Conn.ConnectionString = @"Integrated Security=true;Initial Catalog=Wachtwoord;Data Source=LAPTOP-PDI9B3LP\SCHOOL";
Conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Connection = Conn;
// Alles selecteren van tabel Favorieten
cmd.CommandText = "select * from gebruik";
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
// Tabel wegschrijven in Applicatie
string loginnaam = dr.GetString(0);
cbKeuze.Items.Add(loginnaam);
}
dr.Close();
// Database connectie sluiten
Conn.Close();
}
嘗試在程序的哪裏有一行像_cbKeuze.DataSource = _您可以設置數據源,然後嘗試在組合框中手動添加項目。 – Steve