【发布时间】:2018-11-09 15:49:30
【问题描述】:
我正在尝试从 Visual Studio 执行 pl\sql 过程。基本上我想要做的是传递一些参数并使用它们我试图将值插入到不同的表中。该过程使用游标并将值插入表中,之后我将删除该表以供下次使用。使用 cursor 获得的表格需要最终显示在 gridbox 上。但是下面的程序没有显示任何内容。有人可以帮我解决这个问题吗?
DB_connect();
String x3 = "google";
String x1;
String x2;
String s1 = "delete from temp";
OracleCommand comm = new OracleCommand(s1, conn);
comm.ExecuteNonQuery();
System.Data.OracleClient.OracleCommand comm2 = new System.Data.OracleClient.OracleCommand();
String s2 = "exec cv";
comm2.CommandText = s2;
comm2.CommandType = CommandType.StoredProcedure;
comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;
comm2.Parameters.Add("y", System.Data.OracleClient.OracleType.Number).Value = comboBox2.Text;
comm2.ExecuteNonQuery();
String s3 = "select * from temp";
OracleCommand comm3 = new OracleCommand(s3, conn);
OracleDataAdapter MyAdapter3 = new OracleDataAdapter();//adapter acts as interface btw database and dataset(which is collectio of tables)
MyAdapter3.SelectCommand = comm;
DataTable dTable3 = new DataTable();//datatable represents a single table in database
MyAdapter3.Fill(dTable3);
dataGridView1.DataSource = dTable3;
conn.Close();
这是我的存储过程:
create or replace procedure cv(x in int, y in int, z in varchar)
as
cursor c
is
select email, collegename, cgpa, compname
from student_cv
where (cgpa >= x and yearsofexp >= y) and compname = z;
tem c%rowtype;
begin
open c;
loop
fetch c into tem;
exit when c%notfound;
insert into temp
values(tem.email, tem.collegename, tem.cgpa, tem.compname);
end loop;
end;
/
编辑:
【问题讨论】:
-
您是否测试过该过程实际上返回了任何值?
-
我的程序在 sql plus 中运行,但在从 Visual Studio 执行此程序时出现此错误
-
一般来说,最好只运行一个查询或一个视图,甚至创建一个返回对象/行类型、对象表,甚至是你的引用的函数可以打开和阅读。写入临时数据只是为了在另一端读取它应该是最后的后备。
-
打开您的连接:
conn.Open();在您对数据存储执行任何操作之前。也不清楚conn的位置。这是某个地方的全局(静态)字段吗?如果是这样,可能存在多个线程同时尝试打开/关闭此连接的竞争条件(例如具有多个请求的 Web 应用程序)。
标签: c# sql .net oracle visual-studio