Problem Assigning value from array to textbox

I'm getting the error message when I use the dropdown box to pass a value to the database thru a stored proc and return another value.  Through debugging I've determined that the array is indeed getting filled with one value, but when I try to place this value in the textbox I get the error.  Also, when I removed the val() from around the array variable name and just had the .ToString() there, it did not error but passed the text 'Ticket' to the text box, which is the class name?!?

Thanks a bunch for any help,

Argument 'Expression' cannot be converted to type 'Ticket'. 
Exception Details: System.ArgumentException: Argument 'Expression' cannot be converted to type 'Ticket'.
Line 23:      arTx = GetIT.GetTickets(strCustName)
Line 24: 
Line 25(KABOOM):  Me.TicketNo.Text = Val(arTx(0)).ToString()  
Here is entire function:
    Private Sub GetEmployeesTickets(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CustNames.SelectedIndexChanged
        Dim GetIT As New DOTIT
        Dim strCustName As String
        Dim arTx As ArrayList
        'strCustName = Val(Me.CustNames.SelectedItem)
        If Page.IsPostBack Then
            strCustName = CustNames.SelectedItem.ToString()
            arTx = GetIT.GetTickets(strCustName)
            Me.TicketNo.Text = Val(arTx(0)).ToString() 
        End If
    End Sub
'Function being called:
Public Function GetTickets(ByVal strCustID As String) As ArrayList
        'pg 271
        Dim connectionString As String = ConfigurationManager.ConnectionStrings("DOTITConnectionString").ConnectionString()
        Dim con As New SqlConnection(connectionString)
        Dim cmd As New SqlCommand("pr_GetTickets", con)
        cmd.CommandType = CommandType.StoredProcedure
        cmd.Parameters.Add(New SqlParameter("@CustID", SqlDbType.VarChar))
        cmd.Parameters("@CustID").Value = strCustID
        Dim arTickets As New ArrayList
        Dim reader As SqlDataReader = cmd.ExecuteReader()
        Do While reader.Read()
              Dim Ticks As New Ticket(reader("TicketID")) 
        Return arTickets
    End Function
End Class
'Ticket class:
Public Class Ticket
    Dim intTicketID As Integer
    Public Sub New(ByVal intTicketID As Integer)                 Me.TicketID = intTicketID
    End Sub
    Public Property TicketID() As Integer
            Return intTicketID
        End Get
        Set(ByVal value As Integer)
            intTicketID = value
        End Set
    End Property
End Class

Open in new window

Who is Participating?
BinuthConnect With a Mentor Commented:
Me.TicketNo.Text = CType(arTx(0), Ticket).TicketID.ToString()

insteed of

 Me.TicketNo.Text = Val(arTx(0)).ToString()

You getting error bcoz ... val() function returns decimal type so this need correct Argument
Does it make a difference on the line that blows up if you actually reference the TicketId property?   Maybe something like   Val(arTx(0).TicketId).ToString().  This may not work unless you CType the array item  like   Val(CType(arTx(0),Ticket).TicketId).  

Another possiblity would be in your Ticket class to override the ToString method to return the TicketId.   Then instead of it returning the word Ticket, it would return the TicketId instead.
MoonDoggieAuthor Commented:
Perfect, thanks!
MoonDoggieAuthor Commented:
So I'm trying to understand exactly what is going on here.  Am I passing the class object Ticket within an array then grabbing the property TicketID out of it?  If so is this the cleanest way to do it or should I be just passing the integer value of TicketID in the array?  Thanks.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.