【发布时间】:2014-02-12 13:11:17
【问题描述】:
我正在尝试从视图模型将存储过程调用到 ActionResult 中。
当我尝试运行我的代码时出现错误
IndexOutOfRangeException 由用户代码处理 - 位置 0 无行
这是一个新创建的表并且是空的,但是为什么不触发存储过程来插入数据?这是我的代码。
调用过程 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 控制器
[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);
}
【问题讨论】:
-
您是否曾经在 Google 中搜索过您的异常消息?您在哪一行收到此错误?
-
这里出现错误 secReqOutRow = taOut.GetDataBySecureGUID(request.ToByteArray())[0];
-
您应该先检查
secReqOutRow是否包含数据,然后再放入索引器。 -
您的 using 语句缺少右大括号并且分号错误。可能只是一个错字?
-
@Abbas,另一种方式是正确的 - 在将任何内容分配给
secReqOutRow之前,他应该在将索引器放入之前验证GetDataBySecureGUID是否包含数据。
标签: c# asp.net-mvc stored-procedures model-view-controller exception-handling