I have this code in Visual Studio:
sqlite.Open(); //Initiate connection to the db
string stmEP = "select a.portata,a.quantita,b.QUANTITA_ATTUALE,a.COSTO_UNITARIO,a.SPESA_PORTATA from ORDINI a join QUANTITA_LIMITATE b on a.PORTATA = b.PORTATA WHERE a.CASSA = '" + MyGlobals.NOME_CASSA + "' ORDER BY a.ID,a.PORTATA;";
using var cmdEP = new SQLiteCommand(stmEP, sqlite);
using SQLiteDataReader rdrEP = cmdEP.ExecuteReader();
while (rdrEP.Read())
{
string OUT_PORTATA = (string)rdrEP["a.portata"];
Int64 OUT_QTA = (Int64)rdrEP["a.quantita"];
Int64 OUT_QTA_ATT = (Int64)rdrEP["b.QUANTITA_ATTUALE"];
MessageBox.Show(OUT_PORTATA);
}
sqlite.Close();
The error occurs on this line:
string OUT_PORTATA = (string)rdrEP["a.portata"];
Error:
System.IndexOutOfRangeException: Index was outside the bounds of the array
I don't understand why.
I'd like to extract all items in ORDINI
that are also in QUANTITA_LIMITATE
.
I have this code in Visual Studio:
sqlite.Open(); //Initiate connection to the db
string stmEP = "select a.portata,a.quantita,b.QUANTITA_ATTUALE,a.COSTO_UNITARIO,a.SPESA_PORTATA from ORDINI a join QUANTITA_LIMITATE b on a.PORTATA = b.PORTATA WHERE a.CASSA = '" + MyGlobals.NOME_CASSA + "' ORDER BY a.ID,a.PORTATA;";
using var cmdEP = new SQLiteCommand(stmEP, sqlite);
using SQLiteDataReader rdrEP = cmdEP.ExecuteReader();
while (rdrEP.Read())
{
string OUT_PORTATA = (string)rdrEP["a.portata"];
Int64 OUT_QTA = (Int64)rdrEP["a.quantita"];
Int64 OUT_QTA_ATT = (Int64)rdrEP["b.QUANTITA_ATTUALE"];
MessageBox.Show(OUT_PORTATA);
}
sqlite.Close();
The error occurs on this line:
string OUT_PORTATA = (string)rdrEP["a.portata"];
Error:
System.IndexOutOfRangeException: Index was outside the bounds of the array
I don't understand why.
I'd like to extract all items in ORDINI
that are also in QUANTITA_LIMITATE
.
1 Answer
Reset to default 1When you qualify a column name in a SELECT
statement, that's only to specify the source. the output just has the column name. That means that your column is named "portata", not "a.portata". You should have seen this for yourself because you should have actually looked at the data to see what the column names were.