我想用存储过程“ spValidateDBA”中的refcursor参数UserRole的值填充数据表,但每次都会出现此错误:
列“ UserRole”不属于表。
C#代码:-
string sConnectionString = "Data Source=XE;User ID=sys;Password=system;DBA PRIVILEGE=sysdba";
OracleConnection myConnection = new OracleConnection(sConnectionString);
OracleCommand myCommand = new OracleCommand("spValidateDBA", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
myCommand.CommandText = "spValidateDBA";
myCommand.Parameters.Add("UserId", OracleDbType.Varchar2, 50);
myCommand.Parameters["UserId"].Value = txtUsrId.Text.ToString().ToUpper();
myCommand.Parameters.Add("UserRole",OracleDbType.RefCursor, 50).Direction = ParameterDirection.Output;
myCommand.Parameters.Add("UserIdOut", OracleDbType.Varchar2, 50).Direction = ParameterDirection.Output;
var rolechk = false;
string checkrole = "DBA";
myConnection.Open();
myCommand.ExecuteReader();
// Create the OracleDataAdapter
OracleDataAdapter da = new OracleDataAdapter(myCommand);
DataTable dt = new DataTable();
da.Fill(dt); // Trying to populate a DataTable with refcursor UserRole.
if (myCommand.Parameters["UserIdOut"].Value.ToString().ToUpper() == txtUsrId.Text.ToString().ToUpper())
{
CustomMsgbox.Show("1", "DB Utilities Tool", "OK", "Cancel");
foreach (DataRow dr in dt.Rows)
{
if (dr["UserRole"].ToString().ToUpper().Equals(checkrole)==true)//getting the error "Column 'UserRole' does not belong to table." here
{
CustomMsgbox.Show("\tLogin Successful..!!\t" + Environment.NewLine + "Welcome to DB Utilities Tool", "DB Utilities Tool", "OK", "Cancel");
DBA dba = new DBA();
dba.Show();
this.Hide();
rolechk = true;
break;
}
}
if (!rolechk)
{
CustomMsgbox.Show("Insufficient privileges", "DB Utilities Tool", "OK", "Cancel");
myConnection.Close();
}
else
CustomMsgbox.Show("Please enter correct User ID/Password", "DB Utilities Tool", "OK", "Cancel");
}
存储过程spValidateDBA
create or replace PROCEDURE spValidateDBA(
UserId IN VARCHAR2,
UserRole OUT SYS_REFCURSOR,
UserIdOut OUT VARCHAR2)
AS
BEGIN
select USERNAME into UserIdOut from DBA_USERS DU where DU.USERNAME=UserId;
OPEN UserRole FOR
select GRANTED_ROLE from DBA_USERS DU,DBA_ROLE_PRIVS DRP where DU.USERNAME=UserId AND DU.USERNAME=DRP.GRANTEE;
END spValidateDBA;
最佳答案
您只在游标查询中检索一列GRANTED_ROLE
:
打开用户角色
从DBA_USERS DU中选择GRANTED_ROLE,.......
但是,您尝试从游标中获取UserRole
列。
如果(dr [“ UserRole”]。ToString()。ToUp .........
那里没有任何名为UserRole
的列,您只能获取GRANTED_ROLE
。