Hello together
I developed a little Windows App with 2 Listfields (named LstAnzeige and LstAnzeige1) and SQL Database in the Background.
Now i want to delete the Database Entry if the User clicks on the List Entry but the following error appears and the program won't be built:
"Cannot apply indexing with [] to an expression of type 'object' "
Below the Snippet of the "Delete" Button
I developed a little Windows App with 2 Listfields (named LstAnzeige and LstAnzeige1) and SQL Database in the Background.
Now i want to delete the Database Entry if the User clicks on the List Entry but the following error appears and the program won't be built:
"Cannot apply indexing with [] to an expression of type 'object' "
Below the Snippet of the "Delete" Button
C#:
private void DBDelete_Click(object sender, EventArgs e)
{
// DB Zugriff und Daten löschen mit Delete
OleDbConnection con = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
con.ConnectionString = "Provider=SQLNCLI11.1;" + "Data Source=CRONOS-WI764BIT;Initial Catalog=Tageslimit;Persist Security Info=True;User ID=sa;Password=*****;
cmd.Connection = con;
// Prüfen ob im Listenefeld der Nettolohn angeklickt wurde
if (LstAnzeige.Text == "")
{
// falls ja, Meldung an User dass er einen Datensatz anklicken soll
MessageBox.Show("Bitte einen Datensatz auswählen");
return;
}
// Warnung vor DB Delete ausgeben
if (MessageBox.Show("Wollen Sie den ausgewählten " +
"Datensatz wirklich löschen?", "Löschen",
MessageBoxButtons.YesNo) == DialogResult.No)
return;
try
{
// Falls der User Ja geklickt hat, aktiven Datensatz aus DB löschen
con.Open();
cmd.CommandText = "DELETE FROM Limiten WHERE Nettoloh" + "Nettolohn = " + Nettolohn[LstAnzeige.SelectedIndex]; "
MessageBox.Show(cmd.CommandText);
int anzahl = cmd.ExecuteNonQuery();
if (anzahl > 0)
MessageBox.Show("Datensatz gelöscht");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
con.Close();
}