我试图调用一个过程,并使用在代码中执行后得到的值。
我创建了一个过程Getdata
,并从ASP.NET MVC中调用它并尝试使用它。
Oracle过程:
CREATE OR REPLACE PROCEDURE Getdata(v_hr_stk_out out number,v_cr_stk_out out number) 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;
v_hr_stk_out:=v_hr_stk;
v_cr_stk_out :=v_cr_stk;
END;
ASP.NET MVC端:
OracleConnection conn = new OracleConnection(ConfigurationManager.ConnectionStrings["Mycon"].ToString());
conn.Open();
OracleCommand command = new OracleCommand();
command.Connection = conn;
command.CommandText = "Getdata";
command.CommandType = CommandType.StoredProcedure;
OracleDataAdapter adapter = new OracleDataAdapter(command);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
conn.Close();
return View("Home",dataSet);
绑定值在视图中
@using System.Data;
@model DataSet
<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>Dataset.Tables[0]</td>
<td>Dataset.Tables[1]</td>
</tr>
}
</table>
过程中的值应该出现并绑定到视图的相应列中。
当前,调用adapter.Fill(dataSet);
后数据集中没有存储任何值。
我是ASP.NET MVC和Oracle的新手。任何想法将不胜感激
答案 0 :(得分:1)
在ADO.Net中使用填充数据集时,需要使用Ref Cursors获取数据
将您的过程更改为
<div class="parent">
<div class="child">
<input class="detail" placeholder="click into input">
<input class="detail" placeholder="click into input">
<input class="detail" placeholder="click into input">
</div>
</div>
<div class="parent">
<div class="child">
<input class="detail" placeholder="click into input">
<input class="detail" placeholder="click into input">
</div>
</div>
<div class="parent">
<div class="child">
<input class="detail" placeholder="click into input">
</div>
</div>
<button id="select-detail">Select all details of nearest parent to cursor position (open inspector to check)</button>
对于C#,请遵循此link
更新
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;
答案 1 :(得分:0)
在结束过程正文之前尝试添加此行
Select r_stk, vr_stk from dual;