I have the following code that is executed when you click on a button that has the caption "CLOSE TABLE". What the code does is erase all the info from that table in the database! So far it's fine. What I need now is that before I delete them I list the products in a MessageBox so that the user can send the ticket to print and then if the table is closed.
What I do not manage to do is to return the name of the BD product in a variable to be able to show the data to the user.
Here I leave the code that I have:
// CIERRA LA MESA Y ELIMINA TODOS SUS DATOS
private void btnCerrarMesa_Click(object sender, EventArgs e)
{
string nombre = "";
string mesa = this.numMesa.Trim();
String consulta_productos = "Select nombre from Productos where mesa = @mesa";
SQLiteCommand comd = new SQLiteCommand(consulta_productos, conexion);
comd.Parameters.Clear();
comd.Parameters.Add(new SQLiteParameter("@mesa", mesa));
using (SQLiteDataReader read = comd.ExecuteReader())
{
while (read.Read())
{
// he aqui el problema: necesito que el campo "nombre" de mi base de datos sea guardado en esta variable "nombre" de mi función para luego poder mostrarla más abajo en el MessageBox!
nombre = consulta_productos;
}
}
// DE ACÁ PARA ABAJO ANDA BIEN
DialogResult confirmar = MessageBox.Show("¿Cerrar la mesa?", "", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
if (confirmar == DialogResult.OK)
{
String consulta = "DELETE FROM Productos where mesa = @mesa";
SQLiteCommand cmd = new SQLiteCommand(consulta, conexion);
cmd.Parameters.Clear();
cmd.Parameters.Add(new SQLiteParameter("@mesa", mesa));
cmd.ExecuteNonQuery();
f1.cambiarFondoDefecto();
this.Close();
String info = "";
String total = "";
info += "Mesa:" + mesa.ToString() + Environment.NewLine;
// en la variable nombre (que debería ser un arreglo o una lista) me gustaría que se guarden los nombres de los productos de ESA mesa para poder mostrarlos.
MessageBox.Show(info, nombre);
}
}