首页 > 解决方案 > 尝试编写存储过程并将结果绑定到表中的视图中

问题描述

我正在尝试以下面给定的方式调用一个过程,并希望将来自该过程的结果绑定到视图侧的表格中。

我创建了一个过程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存储过程返回,并应绑定在视图端的表中。

实际:卡在存储过程语法出错并且在视图端代码上获取数据绑定后是否合适或没有疑问。

在此处输入图像描述 我是 Oracle 和 ASP.NET MVC 的新手,正在尝试这样做。任何想法将不胜感激

标签: asp.net-mvcoracle

解决方案


问题似乎在于换行符或空格处的 Windows CRLF 字符。Oracle 不会将此视为空白,而是将其视为空字符串。为了解决这个问题,将 CRLF 字符转换为 LF 字符,Oracle 应该会很高兴。

您可以使用 Notepad++ 来查找这些字符。或者只需使用记事本并删除所有空格和换行符,然后重新创建空格和换行符。

分享本次活动后的成果。


推荐阅读