2
我一直在嘗試將DataGridView連接到作爲引用遊標的存儲過程的輸出。我搜索了很多網站和博客,無法解決我遇到的問題。 這是我用於創建在Oracle 11g中的程序代碼:將我的DataGridView綁定到Ref光標
Create or replace package testpkg
as
type T_cursor is ref cursor;
procedure cursor1 (IDp in number, records out T_cursor);
end testpkg;
/
create or replace package body testpkg as
procedure cursor1 (IDp in number, records out T_cursor)
is
temp_records T_Cursor;
begin
open temp_records for
select status,at_time
from shift_records
where employee_id=IDp;
records:=temp_records;
end cursor1;
end testpkg;
/
這是我在C#中使用的代碼,我設計方法 - 應用程序在Windows,EmpSal是在DataGridView名稱:
DataSet ds = new DataSet();
OracleConnection con = new OracleConnection(connString);
OracleCommand cmd = new OracleCommand();
cmd.CommandText = "testpkg.cursor1";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("IDp", OracleDbType.Int16);
cmd.Parameters["IDp"].Direction = ParameterDirection.Input;
cmd.Parameters["IDp"].Value = ID;
cmd.Parameters.Add("records", OracleDbType.RefCursor);
cmd.Parameters["records"].Direction = ParameterDirection.Output;
OracleDataAdapter da = new OracleDataAdapter(cmd);
DataTable dt = new DataTable();
dt.Locale = System.Globalization.CultureInfo.InvariantCulture;
da.Fill(dt);
BindingSource bindingSource1 = new BindingSource();
bindingSource1.DataSource = dt;
EmpSal.DataSource = bindingSource1;
我知道這個C#可能看起來不是很邏輯,這是因爲我從很多博客中引入它並對其進行了很多修改。但仍然得到此錯誤:
InvalidOperationException was unhandled
Operation is not valid due to the current state of the object.
此錯誤在:「da.Fill(dt);」
任何幫助表示讚賞。
它工作!非常感謝:) :) – 2014-08-28 13:09:29
當然沒問題,很高興能成爲服務。另外...您可能需要編輯/刪除帖子中的連接字符串。 ESP。如果它是你在RL中使用的那個。剛注意到這一點。 – jinksPadlock 2014-08-28 16:18:29
完成:D感謝提示我的朋友 – 2014-08-28 17:02:45