.NET ストアドファンクションをキックするには?

ストアドプロシージャではなくストアドファンクションをキックする方法です。

Using cnn As DbConnection = 略
Using cmd As DbCommand = 略
cmd.Connection = cnn 
cmd.CommandType = CommandType.Text
cmd.CommandText = "BEGIN :nReturnValue := FuncAAA.FuncAAA(:nCd); END;"

Dim pRet As DbParameter = 略
pRet.ParameterName = "nReturnValue"
pRet.Direction = ParameterDirection.ReturnValue
pRet.DbType = DbType.Int32
cmd.Parameters.Add(pRet)

Dim pCd As DbParameter = 略
pCd .ParameterName = "nCd"
pCd .Value = 123
pCd .Direction = ParameterDirection.Input
pCd .DbType = DbType.Int32
cmd.Parameters.Add(pCd )

cmd.ExecuteNonQuery()

Console.WriteLine(pRet.Value.ToString)
End Using
End Using

0 件のコメント: