473,387 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

in and out oracle parameters in vb.net result in null errors

so this code works with just the out parameter but then when you add in parameters weird nulls start showing up and also the straight in parameters work too so it is just when there are both in and out parameters. and i have tried the out parameter at end and beginning of parameter list

the part with problems is the in and out parameters do not want to coexist
Expand|Select|Wrap|Line Numbers
  1.             cmd.Parameters.Add("PKEY", OracleDbType.Int64, ParameterDirection.Output)
  2.             For Each kvp As KeyValuePair(Of String, String) In sqlParams
  3.                 Dim newParam As New OracleParameter(kvp.Key, OracleDbType.Varchar2, kvp.Value, Data.ParameterDirection.Input)
  4.                 newParam.Size = 400
  5.                 cmd.Parameters.Add(newParam)
  6.             Next
  7.  
This works

Expand|Select|Wrap|Line Numbers
  1. Public Shared Sub Run_Oracle_Query(ByVal queryToRun As String, ByVal sqlParams As Dictionary(Of String, String))
  2.         Dim dbConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings("ITSS").ConnectionString
  3.         Dim con As OracleConnection = New OracleConnection(dbConnString)
  4.         Dim cmd = con.CreateCommand()
  5.         Try
  6.             con.Open()
  7.             cmd.CommandText = queryToRun
  8.             cmd.CommandType = CommandType.Text
  9.             For Each kvp As KeyValuePair(Of String, String) In sqlParams
  10.                 cmd.Parameters.Add(kvp.Key, kvp.Value)
  11.  
  12.             Next
  13.             cmd.ExecuteNonQuery()
  14.             'log all sql queryies very expensive operation
  15.             LogThisString("Log All queries: " & queryToRun, "Always")
  16.         Catch ex As OracleException ' catches only Oracle errors
  17.             OracleExceptionLogging(ex.Number, queryToRun, ex)
  18.         Catch ex As Exception
  19.             LogThisString("General Error SQL: " + ex.Message.ToString(), "Always")
  20.             ' MsgBox("Could Not Perform This Database Operation")
  21.         Finally
  22.             con.Close()
  23.             cmd.Dispose()
  24.             con.Dispose()
  25.         End Try
  26.     End Sub
  27.  
This works

Expand|Select|Wrap|Line Numbers
  1.   Public Shared Function Run_Insert_Oracle_Query_Return_ID(ByVal queryToRun As String, ByVal IDcolumnName As String) As String
  2.         Dim dbConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings("ITSS").ConnectionString
  3.         Dim con As OracleConnection = New OracleConnection(dbConnString)
  4.         Dim cmd = con.CreateCommand()
  5.         Dim strUkey As String = ""
  6.         Try
  7.             con.Open()
  8.             cmd.CommandText = queryToRun & " RETURNING " & IDcolumnName & " INTO :UKEY"
  9.             cmd.CommandType = CommandType.Text
  10.             cmd.Parameters.Add("PKEY", OracleDbType.Int64, ParameterDirection.Output)
  11.             cmd.ExecuteNonQuery()
  12.             strUkey = cmd.Parameters("PKEY").Value.ToString
  13.             Return strUkey
  14.         Catch ex As OracleException ' catches only Oracle errors
  15.             OracleExceptionLogging(ex.Number, queryToRun, ex)
  16.  
  17.         Catch ex As Exception
  18.             LogThisString("General Error SQL: " + ex.Message.ToString(), "Always")
  19.             PopupMsgBox("Database Error", "Database Integrity Constants Violated SQL Operation Will Not Be Executed")
  20.         Finally
  21.             con.Close()
  22.             cmd.Dispose()
  23.             con.Dispose()
  24.         End Try
  25.  
  26.         Return strUkey
  27.     End Function
  28.  
This does not work

Expand|Select|Wrap|Line Numbers
  1. Public Shared Function Run_Insert_Oracle_Query_Return_ID(ByVal queryToRun As String, ByVal IDcolumnName As String, ByVal sqlParams As Dictionary(Of String, String)) As String
  2.  
  3.         Dim dbConnString As String = System.Configuration.ConfigurationManager.ConnectionStrings("ITSS").ConnectionString
  4.         Dim con As OracleConnection = New OracleConnection(dbConnString)
  5.         Dim cmd = con.CreateCommand()
  6.         Dim strUkey As String = ""
  7.         Try
  8.             con.Open()
  9.             cmd.CommandText = queryToRun & " RETURNING " & IDcolumnName & " INTO :UKEY"
  10.             cmd.CommandType = CommandType.Text
  11.             cmd.Parameters.Add("PKEY", OracleDbType.Int64, ParameterDirection.Output)
  12.             For Each kvp As KeyValuePair(Of String, String) In sqlParams
  13.                 Dim newParam As New OracleParameter(kvp.Key, OracleDbType.Varchar2, kvp.Value, Data.ParameterDirection.Input)
  14.                 newParam.Size = 400
  15.                 cmd.Parameters.Add(newParam)
  16.             Next
  17.             cmd.ExecuteNonQuery()
  18.             strUkey = cmd.Parameters("PKEY").Value.ToString
  19.             Return strUkey
  20.         Catch ex As OracleException ' catches only Oracle errors
  21.             OracleExceptionLogging(ex.Number, queryToRun, ex)
  22.  
  23.         Catch ex As Exception
  24.             LogThisString("General Error SQL: " + ex.Message.ToString(), "Always")
  25.             PopupMsgBox("Database Error", "Database Integrity Constants Violated SQL Operation Will Not Be Executed")
  26.         Finally
  27.             con.Close()
  28.             cmd.Dispose()
  29.             con.Dispose()
  30.         End Try
  31.  
  32.         Return strUkey
  33.     End Function
Jun 28 '14 #1
1 2580
crap so i guess it does look for order asnd the output does need to be at end like this.....this works solved my own problem

Expand|Select|Wrap|Line Numbers
  1.             For Each kvp As KeyValuePair(Of String, String) In sqlParams
  2.                 Dim newParam As New OracleParameter(kvp.Key, OracleDbType.Varchar2, kvp.Value, Data.ParameterDirection.Input)
  3.                 newParam.Size = 400
  4.                 cmd.Parameters.Add(newParam)
  5.             Next
  6. cmd.Parameters.Add("PKEY", OracleDbType.Int64, ParameterDirection.Output)
Jun 28 '14 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: siva | last post by:
Hi, I saw your post on oracleParameterCollection Bug in MSDN news groups reg: OracleParameterCollection and OracleCommand bug.
0
by: JWM | last post by:
I am trying to implement Oracle connection pooling for the following code, which was written by someone else. Here is my main question -- this java file creates code that is executed every hour,...
1
by: JBBHF | last post by:
Hi i'm working on a web project, and i would like to make my oracle query work in mysql. select match.numero "nummatch", to_char(match.datematch, 'yyyy-MM-dd') "datematch", p1.numjoueur "j1",...
30
by: Michael B Allen | last post by:
I have a general purpose library that has a lot of checks for bad input parameters like: void * linkedlist_get(struct linkedlist *l, unsigned int idx) { if (l == NULL) { errno = EINVAL;...
5
by: tshad | last post by:
I have the following code: *************************************************************************** Dim CommandText as String = "INSERT INTO ftsolutions.dbo.position (client,dateposted) VALUES...
0
by: cetram | last post by:
Hello! I'm trying to fix an appliaction created using ColdFusion MX and Oracle 9i. The application worked fine until our IT department reinstalled the oracle server. As far as I've been able to...
0
by: vbDavidC | last post by:
I am adding a new record to an Access table. This is a sample table with only 1 field which is a primary key. I can add the record ok if it is not a dup (or null). I am trying to learn the...
9
by: BillCo | last post by:
I'm new to SQL Server, so if I'm doing anything stupid don't be mean :) I have a procedure that I use to return data based on optional parameters. It works fine, except when the underlying data...
0
by: pbaillard | last post by:
Here a sample to call a stored procedure with an Oracle Database. odc.Connection = m_cDb ' use an open connection to your database odc.CommandType = CommandType.StoredProcedure odc.CommandText =...
2
by: Ruslan A Dautkhanov | last post by:
Hello ! I'm about to install O9i on FreeBSD box. uname -a: FreeBSD stat2.scn.ru 5.2.1-RELEASE-p3 FreeBSD 5.2.1-RELEASE-p3 #2: Fri Apr 23 19:19:43 KRAST 2004...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.