如何使用asp.net c#
在ADO.NET中调用以下oracle函数 CREATE FUNCTION AuthenticateUser(UserName IN VARCHAR2,Password IN VARCHAR2)
RETURN NUMBER
IS
Counts NUMBER;
rval Number;
BEGIN
SELECT COUNT(USERNAMES)
INTO Counts
FROM tblUsers WHERE USERNAMES = UserName AND PASSWORDS = Password;
IF Counts = 1 THEN
rval:=1;
ELSE
rval:=-1;
END IF;
RETURN(rval);
END;
答案 0 :(得分:0)
首先你需要Oracle ADO.NET库(类似Oracle.DataAccess.dll
?),我不知道你在哪里获得它,但Oracle应该能够帮助它。完成后,您将使用它提供的对象来执行查询。例如,如果要从查询中填充DataSet
,它可能如下所示:
using (var connection = new OracleConnection(ConfigurationManager.ConnectionStrings["OracleDB"].ConnectionString))
using (var command = new OracleCommand(query, connection))
using (var dataAdapter = new OracleDataAdapter(command))
using (var dataSet = new DataSet())
{
connection.Open();
dataAdapter.Fill(dataSet);
connection.Close();
return dataSet;
}
请注意来自该库的OracleConnection
和OracleCommand
等对象。只要您拥有有效的Oracle连接字符串,这些对象就可以正常工作:
<add name="OracleDB" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=some.host.name)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=DEV)));User Id=username;Password=password;"
providerName="Oracle" />
答案 1 :(得分:0)
我认为这应该有效。这预先假定您已将您的连接正确设置到&#34; conn&#34;对象
OracleCommand cmd = new OracleCommand(@"select AuthenticateUser(:USER, :PASS) " +
"from dual", conn);
cmd.Parameters.Add(new OracleParameter("USER", OracleDbType.VarChar));
cmd.Parameters.Add(new OracleParameter("PASS", OracleDbType.VarChar));
cmd.Parameters[0].Value = "yoda";
cmd.Parameters[1].Value = "jed1!";
int result = (int)cmd.ExecuteNonQuery();
另外,我知道内联SQL是不鼓励的,但我希望这会证明这个概念。