Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Implicit conversion - HELP!!!

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    102

    Resolved [RESOLVED] [2005] Implicit conversion - HELP!!!

    I have an enumerated list of integers, which I'm trying to read from a SqlDataReader and pass into a method as an argument.

    Because I have the "Option Strict On", the IDE is complaining that I must convert the value to the enumerated value (the list is already declared as an integer!?!??!

    My enumerated list:
    Code:
    Public Enum StockItemType As Integer
        INGREDIENT = 0
        PACKAGING = 1
        UTENSIL = 2
    End Enum
    Reading in the value:
    Code:
                While rdrSQL.Read()
                    Me.Items.Add(New StockItem(.GetInt32(0), .GetString(1), .GetInt32(2)))
                End While
    My method (instantiates a new class object):
    Code:
        Public Sub New(ByVal ID As Integer, Optional ByVal Name As String = "",  Optional ByVal StockType As StockItemType = StockItemType.INGREDIENT)
            Initialize(ID, Name)
        End Sub
    I've tried CInt, but that still prompts the error. The database value has been changed from a TinyInt value to an Int, just to see if it would resolve the problem but unfortunately, not so.

    Any ideas? Any help would be greatly appreciated.

    P.S. Advice on having the database value set to a TinyInt value, and still having the enumerated list construct and method/argument still working would also be of great help!

    Thanks.

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Implicit conversion - HELP!!!

    I don't see where you are using StockItemType.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    102

    Re: [2005] Implicit conversion - HELP!!!

    Please check again.

    I initially had the wrong constructor (I have 2 constructior methods declared) method on the example, but I re-edited the message.

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: [2005] Implicit conversion - HELP!!!

    1) It's recommended that you don't use optional parameters in .NET, but rather overloaded functions instead (one with the parameter, one without). Not mandatory, not required, just highly suggested.
    2) Because your parameter type is of type StockItemType the value passed in must be of the same type - Even though both are of the same BASE type (integer), the enumerated type becomes a super type.
    Solution:
    1) change the parameter type back to Integer. And leave the rest as it is. Simple, easy, but you lose the intellisense when typing in the calls to the function
    2) CTYpe the value from the Reader to type StockItemType. This route is probably safer, and would be safer still if the value was extracted to a varaible of type StockItemType first, within a Try Catch, that way if in the off chance an invalid value is passed (say, like 4), you can catch that upfront.

    -=tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Aug 2007
    Posts
    102

    Re: [2005] Implicit conversion - HELP!!!

    Thanks techgnome.

    The 2nd solution worked a treat and I think is a better alternative to your 1st as it preserves the data integrity to some extent.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width