从 vb.net 应用程序重新调整值插入 Oracle DB
Inserting in Oracle DB from vb.net application retuning value
我正在继续学习使用 Oracle...但并不那么容易...
我想插入一个带有参数和 return 值
Public Function InsertMapping(GeneralDatas As List(Of String)) As Decimal
Dim idobj As Decimal = 4563
Dim Ref As String = "A85693_B"
Dim nbversion = 1
Dim idroutting As Decimal
Using con As OracleConnection = GetConnexion()
cmd As New OracleCommand With {.Connection = con}
cmd.CommandText = "insert into ROUTING
(DESCRIPTION, DRAFT_NUMBER, DRAFT_VERSION,
ESTIMATE,ID_COMPANY,ID_CUSTOMER,ID_ROUTING_TYPE,
ID_STATUS,REFERENCE,RELEASE,REVISION,SCRAP_PCENT,
SCRAP_QUANTITY,VERSION,ID_OBJECT)
values(:desc,:noplan,:indplan,0,
1,:idclt,4,381,
:ref,0,0,0,0,
:voir,:idobj) returning ID_ROUTING into :monid"
cmd.CommandType = CommandType.Text
Dim prm = New OracleParameter("monid", OracleDbType.Decimal)
prm.Direction = ParameterDirection.ReturnValue
cmd.Parameters.Add(prm)
Dim prm1 = New OracleParameter("desc", OracleDbType.Varchar2)
prm1.Direction = ParameterDirection.Input
prm1.Value = ""
cmd.Parameters.Add(prm1)
Dim prm2 = New OracleParameter("noplan", OracleDbType.Varchar2)
prm2.Direction = ParameterDirection.Input
prm2.Value = "Cloison"
cmd.Parameters.Add(prm2)
Dim prm3 = New OracleParameter("indplan", OracleDbType.Varchar2)
prm3.Direction = ParameterDirection.Input
prm3.Value = ""
cmd.Parameters.Add(prm3)
Dim prm4 = New OracleParameter("idclt", OracleDbType.Decimal)'Number(20,0)
prm4.Direction = ParameterDirection.Input
prm4.Value = 5
cmd.Parameters.Add(prm4)
Dim prm5 = New OracleParameter("ref", OracleDbType.Varchar2)
prm5.Direction = ParameterDirection.Input
prm5.Value = Ref
cmd.Parameters.Add(prm5)
Dim prm6 = New OracleParameter("voir", OracleDbType.Varchar2)
prm6.Direction = ParameterDirection.Input
prm6.Value = "1"
cmd.Parameters.Add(prm6)
Dim prm7 = New OracleParameter("idobj", OracleDbType.Decimal)
prm7.Direction = ParameterDirection.Input
prm7.Value = idobj
cmd.Parameters.Add(prm7)
con.Open()
cmd.ExecuteNonQuery()'<------Error here
HelperJournal.WriteEntry("after excecute")
idroutting = cmd.Parameters("monid").Value.ToString
End Using
HelperJournal.WriteEntry("idroutting", idroutting)
Return idroutting
End Function
这是我的错误信息
Message:ORA-01745: nom de variable hôte/attachée (bind) non valide
Exception:Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-01745: nom de variable hôte/attachée (bind) non valide
à OracleInternal.ServiceObjects.OracleConnectionImpl.VerifyExecution(Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, SqlStatementType sqlStatementType, Int32 arrayBindCount, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone)
à OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, OracleException& exceptionForArrayBindDML, OracleConnection connection, OracleLogicalTransaction& oracleLogicalTransaction, Boolean isFromEF)
à Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
看了那么多遍都没看到参数什么链接不好...
感谢您的帮助
这个
Dim prm = New OracleParameter("monid", OracleDbType.Decimal)
prm.Direction = ParameterDirection.ReturnValue
应该在最后,方向应该是输出
' all parameters first ^^^
Dim prm = New OracleParameter("monid", OracleDbType.Decimal)
prm.Direction = ParameterDirection.Output ' <-- here
con.Open()
cmd.ExecuteNonQuery()
此外,ODP OracleCommand
有 BindByName
属性。如果你设置cmd.BindByName = True
,你可以有任意顺序的参数
我正在继续学习使用 Oracle...但并不那么容易... 我想插入一个带有参数和 return 值
Public Function InsertMapping(GeneralDatas As List(Of String)) As Decimal
Dim idobj As Decimal = 4563
Dim Ref As String = "A85693_B"
Dim nbversion = 1
Dim idroutting As Decimal
Using con As OracleConnection = GetConnexion()
cmd As New OracleCommand With {.Connection = con}
cmd.CommandText = "insert into ROUTING
(DESCRIPTION, DRAFT_NUMBER, DRAFT_VERSION,
ESTIMATE,ID_COMPANY,ID_CUSTOMER,ID_ROUTING_TYPE,
ID_STATUS,REFERENCE,RELEASE,REVISION,SCRAP_PCENT,
SCRAP_QUANTITY,VERSION,ID_OBJECT)
values(:desc,:noplan,:indplan,0,
1,:idclt,4,381,
:ref,0,0,0,0,
:voir,:idobj) returning ID_ROUTING into :monid"
cmd.CommandType = CommandType.Text
Dim prm = New OracleParameter("monid", OracleDbType.Decimal)
prm.Direction = ParameterDirection.ReturnValue
cmd.Parameters.Add(prm)
Dim prm1 = New OracleParameter("desc", OracleDbType.Varchar2)
prm1.Direction = ParameterDirection.Input
prm1.Value = ""
cmd.Parameters.Add(prm1)
Dim prm2 = New OracleParameter("noplan", OracleDbType.Varchar2)
prm2.Direction = ParameterDirection.Input
prm2.Value = "Cloison"
cmd.Parameters.Add(prm2)
Dim prm3 = New OracleParameter("indplan", OracleDbType.Varchar2)
prm3.Direction = ParameterDirection.Input
prm3.Value = ""
cmd.Parameters.Add(prm3)
Dim prm4 = New OracleParameter("idclt", OracleDbType.Decimal)'Number(20,0)
prm4.Direction = ParameterDirection.Input
prm4.Value = 5
cmd.Parameters.Add(prm4)
Dim prm5 = New OracleParameter("ref", OracleDbType.Varchar2)
prm5.Direction = ParameterDirection.Input
prm5.Value = Ref
cmd.Parameters.Add(prm5)
Dim prm6 = New OracleParameter("voir", OracleDbType.Varchar2)
prm6.Direction = ParameterDirection.Input
prm6.Value = "1"
cmd.Parameters.Add(prm6)
Dim prm7 = New OracleParameter("idobj", OracleDbType.Decimal)
prm7.Direction = ParameterDirection.Input
prm7.Value = idobj
cmd.Parameters.Add(prm7)
con.Open()
cmd.ExecuteNonQuery()'<------Error here
HelperJournal.WriteEntry("after excecute")
idroutting = cmd.Parameters("monid").Value.ToString
End Using
HelperJournal.WriteEntry("idroutting", idroutting)
Return idroutting
End Function
这是我的错误信息
Message:ORA-01745: nom de variable hôte/attachée (bind) non valide Exception:Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-01745: nom de variable hôte/attachée (bind) non valide à OracleInternal.ServiceObjects.OracleConnectionImpl.VerifyExecution(Int32& cursorId, Boolean bThrowArrayBindRelatedErrors, SqlStatementType sqlStatementType, Int32 arrayBindCount, OracleException& exceptionForArrayBindDML, Boolean& hasMoreRowsInDB, Boolean bFirstIterationDone) à OracleInternal.ServiceObjects.OracleCommandImpl.ExecuteNonQuery(String commandText, OracleParameterCollection paramColl, CommandType commandType, OracleConnectionImpl connectionImpl, Int32 longFetchSize, Int64 clientInitialLOBFS, OracleDependencyImpl orclDependencyImpl, Int64[]& scnFromExecution, OracleParameterCollection& bindByPositionParamColl, Boolean& bBindParamPresent, OracleException& exceptionForArrayBindDML, OracleConnection connection, OracleLogicalTransaction& oracleLogicalTransaction, Boolean isFromEF) à Oracle.ManagedDataAccess.Client.OracleCommand.ExecuteNonQuery()
看了那么多遍都没看到参数什么链接不好... 感谢您的帮助
这个
Dim prm = New OracleParameter("monid", OracleDbType.Decimal)
prm.Direction = ParameterDirection.ReturnValue
应该在最后,方向应该是输出
' all parameters first ^^^
Dim prm = New OracleParameter("monid", OracleDbType.Decimal)
prm.Direction = ParameterDirection.Output ' <-- here
con.Open()
cmd.ExecuteNonQuery()
此外,ODP OracleCommand
有 BindByName
属性。如果你设置cmd.BindByName = True
,你可以有任意顺序的参数