Include the nuget package Oracle.ManagedDataAccess
in your project (This is a driver
connection to the database Oracle
).
Import these two namespaces into your code:
Imports Oracle.ManagedDataAccess.Client
Imports Oracle.ManagedDataAccess.Types
- To create a parameter do as follows:
Dim rgCidadaoParameter As OracleParameter = oracleCommand.CreateParameter()
rgCidadaoParameter.ParameterName = "p_rg_cidadao"
rgCidadaoParameter.OracleDbType = OracleDbType.Varchar2
rgCidadaoParameter.Size = 4096
rgCidadaoParameter.Value = "1.111.111"
oracleCommand.Parameters.Add(rgCidadaoParameter)
You can also change the "direction" of your parameter to indicate if it is of type IN
, OUT
or RETURNVALUE
(That serves to receive values of functions
).
This is the default value and serves for type parameters IN
:
rgCidadaoOutParameter.Direction = ParameterDirection.Input
To OUT
:
rgCidadaoOutParameter.Direction = ParameterDirection.Output
For returns of functions:
rgCidadaoOutParameter.Direction = ParameterDirection.ReturnValue.
Below is a practical example based on your question:
Dim connectionString As String = "Data Source=banco;User ID=usuario;Password=senha;"
Using oracleConnection As OracleConnection = New Oracle.ManagedDataAccess.Client.OracleConnection(connectionString)
oracleConnection.Open()
Dim oracleCommand As OracleCommand = oracleConnection.CreateCommand()
oracleCommand.CommandType = CommandType.StoredProcedure
oracleCommand.CommandText = "pr_consulta_rg_site"
Dim rgCidadaoParameter As OracleParameter = oracleCommand.CreateParameter()
rgCidadaoParameter.ParameterName = "p_rg_cidadao"
rgCidadaoParameter.OracleDbType = OracleDbType.Varchar2
rgCidadaoParameter.Size = 4096
rgCidadaoParameter.Value = "1.111.111"
oracleCommand.Parameters.Add(rgCidadaoParameter)
Dim rgCidadaoOutParameter As OracleParameter = oracleCommand.CreateParameter()
rgCidadaoOutParameter.ParameterName = "p_rg_cidadao_o"
rgCidadaoOutParameter.OracleDbType = OracleDbType.Varchar2
rgCidadaoParameter.Size = 4096
rgCidadaoOutParameter.Direction = ParameterDirection.ReturnValue
oracleCommand.Parameters.Add(rgCidadaoOutParameter)
Dim result As Int32 = oracleCommand.ExecuteNonQuery()
Dim rgCidadaoOut As OracleString = rgCidadaoOutParameter.Value
Console.WriteLine(rgCidadaoOut.Value)
End Using
You should write here the most relevant parts of the link that solve the OP issue.
– Gabriel