Deleting a row from the grid works, but for some reason it is not removed from the database. The bd.sqlite table is the tovari table.

private void button4_Click(object sender, EventArgs e) { int ind = dataGridView1.SelectedCells[0].RowIndex; dataGridView1.Rows.RemoveAt(ind); m_dbConn = new SQLiteConnection("Data Source=" + dbFileName + ";Version=3;"); m_dbConn.Open(); m_sqlCmd.Connection = m_dbConn; string del = "DELETE FROM tovari WHERE id"; SQLiteCommand command = new SQLiteCommand(del, m_dbConn); } 

    1 answer 1

    Judging by the code section, there is not enough call command.ExecuteNonQuery (). And it is even better to wrap the SQLiteConnection in using, so as not to forget to close the connection.

    • It crashes when adding command.ExecuteNonQuery (). - goga
    • @goga And with what error? - iElk
    • one
      @goga 1. You call the ExecuteNonQuery method on the wrong object. (your command is the command variable). 2. You do not correctly in the text of the request pass the value of the variable ind, it is necessary so "DELETE FROM tovari WHERE id =" + ind. And yet, are you sure that the line number in the grid coincides with the id in the database table? - iElk
    • corrected, no errors, but in the database as well, nothing changes. - goga