0

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 1

1

When 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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank's work fine now!!!
@GianlucaBendinelli, if an answer solves your problem then don't forget to accept it. As well as rewarding the person who answered, it shows up in the question list lets everyone know that you don't need any further help without their having to open the question and read a comment on an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.