我正在使用 C# Windows 窗体应用程序,我在一个复选框中有 5 个项目。现在我必须将这些项目保存到 MS Access 数据库表中。
有谁知道我应该怎么做?(Sprachen = 选中列表框)
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() 尝试它时,它都会给我一个错误:对于至少一个必需的参数,没有指定值。
我只能计算我在复选框中检查了多少项目。
有人有解决方案吗?