I'm trying to get the data from an SQLite query and then save the fields in a list and show them to the user through a MessageBox. I have two problems: 1) I do not know if what I'm doing is fine. 2) I do not compile the code, and I do not know why!
Here I leave what I have:
var lista= new List<string>();
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));
comd.ExecuteNonQuery();
using (SQLiteDataReader read = comd.ExecuteReader())
{
foreach (string i in read)
{
// acá me tira error
lista.Add(read.GetString(i));
}
}
The compiler throws me an error that says "can not convert string to int" in the line that I frame above. I do not understand why. Try putting i.toString () and it does not compile either.
Is the foreach well done? And what do you mean you can not convert string to int if I do not have any int? : /