The following query erases the data coinciding with the search of my database but I only want to delete a single row in case the query matches more than one row of my table.
According to what I understand the query would be well done, with the LIMIT 1
but when executing it throws me the following exception:
An unhandled exception of type 'System.Data.SQLite.SQLiteException' occurred in System.Data.SQLite.dll Additional information: SQL logic error near "LIMIT": syntax error
This is my query:
private void Pagos_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (this.Pagos.Columns[e.ColumnIndex].Name == "colBotones")
{
string mesa = this.numMesa.Trim();
int id_producto = Convert.ToInt32(this.Pagos.Rows[e.RowIndex].Cells[0].Value.ToString());
string nombre = Convert.ToString(this.Pagos.Rows[e.RowIndex].Cells[1].Value.ToString());
double precio = Convert.ToDouble(this.Pagos.Rows[e.RowIndex].Cells[2].Value.ToString());
double cantidad = Convert.ToDouble(this.Pagos.Rows[e.RowIndex].Cells[3].Value.ToString());
double subtotal = Convert.ToDouble(this.Pagos.Rows[e.RowIndex].Cells[4].Value.ToString());
String consulta = "DELETE FROM Productos where mesa = @mesa and @id_producto = id_producto and nombre = @nombre and precio = @precio and cantidad = @cantidad and subtotal = @subtotal LIMIT 1";
SQLiteCommand cmd = new SQLiteCommand(consulta, conexion);
cmd.Parameters.Clear();
cmd.Parameters.Add(new SQLiteParameter("@mesa", mesa));
cmd.Parameters.Add(new SQLiteParameter("@id_producto", id_producto));
cmd.Parameters.Add(new SQLiteParameter("@nombre", nombre));
cmd.Parameters.Add(new SQLiteParameter("@precio", precio));
cmd.Parameters.Add(new SQLiteParameter("@cantidad", cantidad));
cmd.Parameters.Add(new SQLiteParameter("@subtotal", subtotal));
cmd.ExecuteNonQuery();
Pagos.Rows.RemoveAt(Pagos.CurrentRow.Index);
}
}
Does anyone know what may be happening?