我使用C#Windows窗體應用程序,並且我在清單框中獲得了5個項目。 現在我必須將這些項目保存到MS Access數據庫表中。獲取已檢查的項目到MS Access數據庫
有誰知道我應該怎麼做? (Sprachen = checkedlistbox)
private void button1_Click_1(object sender, EventArgs e)
{
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "INSERT INTO Employee (Vorname, Nachname, Wohnort, Geburtstag, Abteilung, Nummer, MKZ, Führerschein, Sprachen) values('" + Vorname.Text + "','" + Nachname.Text + "','" + Wohnort.Text + "','" + Geburtstag.Text + "','" + Abteilung.Text + "','" + Mitarbeiter.Text + "','" + MKZ.Text + "'," + Führerschein.Checked.ToString() + "," + Sprachen.SelectedItems + ")";
command.ExecuteNonQuery();
MessageBox.Show("Daten gespeichert!");
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
}
每次我用的toString()嘗試過,它給我一個錯誤: 對於至少一個必需的參數沒有指定值。
我只能計算我在檢查列表中檢查了多少項。
任何人都有解決方案嗎?
我想,你應該使用單獨的表作爲清單,並插入選中的值作爲每個項目。除非你想做一些瘋狂的東西,並使用任何像字符串的數組。你能發佈你的員工表的表定義嗎? –
「Sprachen」定義的類型是什麼? – Rohit