使用游标和过程时连接已关闭

时间:2018-11-09 20:01:27

标签: c# sql oracle visual-studio oracle11g

我的代码是-

        string oracleb = "Data source=HPPRO58; user ID=system; password=deb;";
        conn = new OracleConnection(oracleb);
        //conn.Open();
        conn.Open();
        String x3 = "google";
        String x1 ;
        String x2;
        String s1 = "delete from temp";
        OracleCommand comm = new OracleCommand(s1, conn);
        comm.ExecuteNonQuery();


        OracleCommand comm2 = new OracleCommand();
        String s2 = "cv";
        comm2.Connection = conn;
        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.Parameters.Add("z", System.Data.OracleClient.OracleType.Number).Value = x3;
        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();

我的错误是-

enter image description here

我也试图运行一个带有游标的过程。因此,我使用了3个comm变量。但是我遇到了以上错误。因此,我想知道如何解决它。

我已经在函数启动时打开了连接,但仍然表明连接已关闭。

编辑-

我的程序名称是简历

新错误- enter image description here

我的程序-

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;
/

第59行是-

comm2.Parameters.Add("x", System.Data.OracleClient.OracleType.Number).Value = comboBox1.Text;

0 个答案:

没有答案