mercredi 11 février 2015

Why does SQLite tell me "No current row"?

The query being sent is good; running it:



SELECT line_id, description, department, upc_pack_size, pack_size, unit_cost, unit_list FROM Inventory WHERE siteNum = "03" AND upc_code = "76145513"


...in LINQPad returns a record with these values:



line_id = 0
description = [empty string]
department = 2.99
upc_pack_size = 333
pack_size = 333
unit_cost = 50.01
unit_list = 50.99


But the code:



public List<String> GetDynamicINVValsForUPCCode(String qry, String siteNum, String upcCode)
{
ExceptionLoggingService.Instance.WriteLog(String.Format("Reached TestHHSDBUtils.GetDynamicINVValsForUPCCode(); siteNum is {0}; upcCode is {1}; qry is {2}", siteNum, upcCode, qry));
List<String> dsdValsForUPCCode = new List<string>();
try
{
using (SQLiteConnection conn = new SQLiteConnection(HHSUtils.GetDBConnection()))
{
conn.Open();
using (SQLiteCommand cmd = new SQLiteCommand(qry, conn))
{
cmd.Parameters.Add(new SQLiteParameter("upcCode", upcCode));
cmd.Parameters.Add(new SQLiteParameter("SiteNum", siteNum));
using (SQLiteDataReader rdr = cmd.ExecuteReader())
{
dsdValsForUPCCode.Add(Convert.ToString(rdr["Line_id"])); // Line_id, int32
dsdValsForUPCCode.Add(Convert.ToString(rdr["Description"])); // Description
dsdValsForUPCCode.Add(Convert.ToString(rdr["Department"])); // Department
dsdValsForUPCCode.Add(Convert.ToString(rdr["Upc_pack_size"])); // Upc_pack_size (int32)
dsdValsForUPCCode.Add(Convert.ToString(rdr["Pack_size"])); // Pack_size (int32)
dsdValsForUPCCode.Add(Convert.ToString(rdr["Unit_qty"])); // Unit_qty (single)
}
}
return dsdValsForUPCCode;
}
}
catch (Exception ex)
{
String msgInnerExAndStackTrace = String.Format("{0}; Inner Ex: {1}; Stack Trace: {2}", ex.Message, ex.InnerException, ex.StackTrace);
ExceptionLoggingService.Instance.WriteLog(String.Format("From TestHHSDBUtils.GetDynamicINVValsForUPCCode: {0}", msgInnerExAndStackTrace));
return null;
}
}


...fails, the err being logged as:



Message: From TestHHSDBUtils.GetDynamicINVValsForUPCCode: No current row; Inner Ex: ; Stack Trace: at System.Data.SQLite.SQLiteDataReader.CheckValidRow()
at System.Data.SQLite.SQLiteDataReader.GetValue(Int32 i)
at System.Data.SQLite.SQLiteDataReader.get_Item(String name)
at HHS.TestHHSDBUtils.GetDynamicINVValsForUPCCode(String qry, String siteNum, String upcCode)


Why does it say "no current row" when there is one?


Aucun commentaire:

Enregistrer un commentaire