Question

I'm tring to call a stored procedure into a ActionResult from the view model.

When I tried to run my code I get an error

IndexOutOfRangeException was handled by user code - No Row at Position 0

This is a newly created table and is empty but why isn't the stored procedure getting fired to insert the data? Here is my code.

Called Procedure CreateSecureRequestOutcome

 public static void CreateSecureRequestOutcome(
 OracleTransaction trans,
 dsAdmin.SECURE_REQUEST_OUTCOMESRow outcomeRow)
  {
   using (OracleCommand cm = new OracleCommand())
  {
   cm.Connection = trans.Connection;
   cm.Transaction = trans;
   cm.CommandText = "TheService.PKG#SECURE_REQUEST.SECURE_REQUEST_OUTCOME";
   cm.CommandType = CommandType.StoredProcedure;
   cm.AddToStatementCache = true;

 OracleParameter param = cm.Paramaters.Add("P_KEEP_PERSON_ID", OracleDBType.Decimal, Paremeter.Direction.Input);
 param.Value = keepPersonID;

 param = cm.Paramaters.Add("P_SECURE_REQUEST_GUID", OracleDBType.Raw, 16, null, Paremeter.Direction.Input);
 param.Value = outcomeRow.SECURE_REQUEST_GUID;

 param = cm.Parameters.Add("P_OUTCOME_TIMESTAMP", OracleDBType.Object, Paremeter.Direction.Output);
  }
}
 cm.ExecuteNonQuery();

IdentityConfirmed ViewModel Controller

[httpPost]
public ActionResult IdentityConfirmed(FormCollection collection)
{
 dsAdmin.SECURE_REQUESTS_OUTCOMESRow secReqOutRow;

using (OracleConnection cn = new OracleConnection (OracleConnectionManager.GetProxyServiceConnetionString()))
{
    cn.Open();
    using (OracleTransaction trans = cn.BeginTransaction())
    {
          using (Data.dsAdminTableAdapters.SECURE_REQUESTS_OUTCOMESTableAdapter taOut = new Data.dsAdminTableAdapters.SECURE_REQUESTS_OUTCOMESTableAdapter();
          {
             typedDatasetFiller.ApplyConnection(taOut, cn);
             secReqOutRow = taOut.GetDataBySecureGUID(request.ToByteArray())[0];
          }
            secReqOutRow.OUTCOME_TIMESTAMP = DateTime.Now.AddMonths(1);
            Support.CreateSecureRequestOutcome(trans, secReqOutRow);
            trans.Commit();
      }
    cn.Close();
  }
 retrun View("IdentityConfirmed", vm);
}
Was it helpful?

Solution

Well, what do you think the error means? Why don't you debug properly?

To make it short, GetDataBySecureGUID returns an empty array, so accessing index 0 is not valid.


Please change your code as follows:

var results = taOut.GetDataBySecureGUID(request.ToByteArray());           
secReqOutRow = results[0];

Now set a breakpoint to the second line and inspect the value of results. How many elements are there?

I bet there's none, because that's exactly what the exception means. You're trying to access an element in a collection using an index that is larger than the maximum allowed index. The fact that you're trying to access the first element and get this error means that there is no first element, so there is no element at all in the collection.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top