最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - System.IndexOutOfRangeException during SELECT output - Stack Overflow

programmeradmin3浏览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.

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.

Share Improve this question edited Mar 15 at 19:23 marc_s 756k184 gold badges1.4k silver badges1.5k bronze badges asked Mar 15 at 15:21 Gianluca BendinelliGianluca Bendinelli 73 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论