Problem Assigning value from array to textbox

Posted on 2008-11-13
Medium Priority
Last Modified: 2012-06-27
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

Question by:MoonDoggie
  • 2
LVL 14

Expert Comment

ID: 22957171
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.
LVL 14

Accepted Solution

Binuth earned 500 total points
ID: 22957235
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

Author Closing Comment

ID: 31516642
Perfect, thanks!

Author Comment

ID: 22961221
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.

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question