asp.net-mvc - 尝试编写存储过程并将结果绑定到表中的视图中
问题描述
我正在尝试以下面给定的方式调用一个过程,并希望将来自该过程的结果绑定到视图侧的表格中。
我创建了一个过程GetData
,希望在数据集中返回值 a 并在视图端绑定而不使用模型。
CREATE OR REPLACE PROCEDURE Getdata(v_hr_stk_out OUT SYS_REFCURSOR) Is
r_stk number;
vr_stk number;
BEGIN
select round(sum(a.batch_wt)) into r_stk from dbprod.sm_data a where a.iss_date is null and a.cw_coil_no is not null and a.prod_cd = '37' and a.from_plant != a.hsource;
select round(sum(a.batch_wt)) into vr_stk from dbprod.psm_data a where a.iss_date is null and a.cw_coil_no is not null and a.prod_cd = 'C9' and a.from_plant != a.hr_source;
OPEN v_hr_stk_out For
select r_stk, vr_stk from dual
END;
C#代码:
conn.Open();
OracleCommand command = new OracleCommand();
command.Connection = conn;
command.CommandText = "Getdata";
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("v_hr_stk_out", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
command.Parameters.Add("v_cr_stk_out", OracleDbType.RefCursor).Direction = ParameterDirection.Output;
OracleDataAdapter adapter = new OracleDataAdapter(command);
DataSet ds = new DataSet();
adapter.Fill(ds);
return View("Home", ds)
看法
<table cellpadding="0" cellspacing="0">
<tr>
<th>A</th>
<th>B/th>
<th>C</th>
</tr>
@foreach (DataRow row in Model.Tables[0].Rows)
{
<tr>
<td>F</td>
<td>@row["r_stk"]</td>
<td>@row["vr_stk"]</td>
</tr>
}
</table>
预期:值应从GetData
存储过程返回,并应绑定在视图端的表中。
实际:卡在存储过程语法出错并且在视图端代码上获取数据绑定后是否合适或没有疑问。
解决方案
问题似乎在于换行符或空格处的 Windows CRLF 字符。Oracle 不会将此视为空白,而是将其视为空字符串。为了解决这个问题,将 CRLF 字符转换为 LF 字符,Oracle 应该会很高兴。
您可以使用 Notepad++ 来查找这些字符。或者只需使用记事本并删除所有空格和换行符,然后重新创建空格和换行符。
分享本次活动后的成果。
推荐阅读
- python - 在 QProcess 中设置不同格式的参数
- node.js - mongodb副本集如何与nodejs-mongoose一起工作?
- python - 在 python 中使用 matplotlib 将 5 x 5 数组(混淆矩阵)转换为表格
- javascript - 你如何通过反应和本地存储将数据保持在状态?
- reactjs - useState 未使用 socket.io 正确更新
- bazel - Bazel:将 Linux 远程执行平台与 Mac OS 本地平台混合
- c++ - Uno 的卡片类向量
- javascript - Firebase 身份验证检测用户是否来自重定向登录
- javascript - 如何从最大化 RAM 修复浏览器 blob 下载?
- curl - 我可以将笑话代码覆盖率添加到来自管道的 Bitbucket 拉取请求中的报告吗