Miscellaneous Debris

Avner Kashtan's Frustrations and Exultations
VB.NET and Enums

I've run into several problems with the way the VB.NET compiler handles enums.

I've described one here, a while ago. In a nutshell, an enum exposed by SPS was based on the non-CLSCompliant UInt32 datatype, and VB.NET was choking on it during compilation.

The second one I ran into recently was when using the Enterprise Library to access an Oracle database. I was trying to create a paramater for an OracleCommandWrapper object. The AddParameter method has the following overloads:

AddParameter(String Name, System.Data.DbType type, ...)
AddParameter(String Name, System.Data.Oracle.OracleType type, ...)

Both overloads accept an enum as the second parameter, and the rest of the arguments are identical. Both enums are based on Int32. When compiling a call to this method, I got a compiler errors saying that no accessible overload was available without a narrowing conversion.

I'm still not entirely sure what this compiler error meant. My suspicion is that since both enums are ultimately the same datatype, it cannot determine which overload to call. I would be glad to know exactly what it means.

The solution for both problems, however, was identical and involved mostly confusing the VB.NET compiler with shiny lights:

Instead of calling AddParameter("Name", OracleType.Cursor, ...), I called it like this: AddParameter("Name", [Enum].Parse(GetType(OracleType), OracleType.Cursor.ToString()), ...).

In effect, I print out the enum value as a string and then re-parse it into an enum. This trick seems to convince the compiler that everything is fine, and it compiles (and runs) smoothly. A simple CType() cast does NOT work. This solution also worked for the UInt32 enum in SPS - the compiler complained that it didn't know what UInt32 was, but once I've perpetrated my little deception, everything was cool.

Anyone more familiar with the VB.NET compiler and can explain this behavior?

Published Friday, July 22, 2005 8:20 PM by AvnerK

Filed under: ,

Comments

# re: VB.NET and Enums@ Friday, July 22, 2005 2:13 PM

I believe you could also do this:

AddParameter("Name", CType(OracleType.Cursor, OracleType), ...),

Wedgebert

# re: VB.NET and Enums@ Friday, July 22, 2005 6:31 PM

I was about to suggest named paramters - but then I noticed that the param name for the oracle version is the same as for the normal version.

bum.

Geoff Appleby

# Really need help. @ Tuesday, August 29, 2006 2:43 PM

error

ORA-06550: line 1, column 7: PLS-00306: wrong number or types of arguments in call to 'SELXCHCONTACTINFO' ORA-06550: line 1, column 7: PL/SQL: Statement ignored

Code

 Public Function BSCoESelectContactInfo(ByVal NtAccount As String) As DataSet

       'Dim database As Database

       Dim database As OracleDatabase

       'database = DatabaseFactory.CreateDatabase

       database = DatabaseFactory.CreateDatabase("Database Instance1")

       Dim selectCommandWrapper As DBCommandWrapper = database.GetStoredProcCommandWrapper("ppi.ata_getdata_pkg.selxchcontactinfo")

       'Dim selectCommandWrapper As OracleCommandWrapper = database.GetStoredProcCommandWrapper("ata_getdata_pkg.selxchcontactinfo")

       selectCommandWrapper.AddInParameter("NtAccount", DbType.String)

       '        selectCommandWrapper.AddOutParameter("refcur", DbType.Object, 20000)

       'selectCommandWrapper.AddParameter("refcur", OracleType.Cursor, 0, ParameterDirection.Output, True, 0, 0, String.Empty, DataRowVersion.Default, Convert.DBNull)

       selectCommandWrapper.AddParameter("refcur", [Enum].Parse(GetType(OracleType), OracleType.Cursor.ToString()), 0, ParameterDirection.Output, True, 0, 0, String.Empty, DataRowVersion.Default, Convert.DBNull)

       Dim connection As IDbConnection = database.GetConnection

       Try

           Dim MyDataSet As DataSet

           MyDataSet = database.ExecuteDataSet(selectCommandWrapper)

           Return MyDataSet

       Catch ex As System.Exception

           Throw

       End Try

   End Function

Any ideas would be greatly helpful,  thanks

Allen Winn

# re: VB.NET and Enums@ Wednesday, February 13, 2008 2:54 PM

Hello everyone I am making an application in C # 2005, and I have the following error will be well appreciated their help:

BDSIGAP.AddParameter(icom, "cli_nit", (DbType)System.Data.OracleClient.OracleType.VarChar, ParameterDirection.Input, cli.cli_nitci, DataRowVersion.Original, Convert.DBNull);

 return BDSIGAP.ExecuteDataSet(icom);

ORA-06550: línea 1, columna 7:

PLS-00306: Number or types of arguments wrong to call 'SP_CLIENTE1'

ayuda porfa

master777

Leave a Comment

(required) 
(required) 
(optional)
(required)