unable to find specified column in result set index out of bounds index out of range exception

10,767

It doesn't appear that your query has a column named "Total_Money". You didn't name the single column your query returns.

Share:
10,767
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    i am having trouble putting a value in a textbox. Each time a ticket is sold i put the total price in a textbox, each time a ticket is sold for the same concert it increases by adding its self to the total price. It works at the first sale, but after that it breaks down. here is the code and thanks in advance.

     Private Function DisplayMoneyTaken() As Integer
        Dim totalMoney As Integer
        'open the database connection
        strSQL = "SELECT MAX(Total_Money) FROM Sales WHERE Concert_Id =" + Mid(cboVenue.Text, 1, 4)
    
        conn.Open()
        cmd.Connection = conn
        cmd.CommandText = strSQL
        cmd.CommandType = CommandType.Text
    
        dr = cmd.ExecuteReader()
    
        'read the record returned
        dr.Read()
        If IsDBNull(dr.Item(0)) Then
            totalMoney = txtPrice.Text
        Else
            DisplayMoneyTaken = dr.Item("Total_Money") + Val(txtPrice.Text)
        End If
    
    
    
        'close the database
        conn.Close()
        Return totalMoney
    
    End Function