locked
Exception Details: System.IndexOutOfRangeException: RRS feed

  • Question

  • User669796193 posted

    I have a question, I'm trying to return sqldatareader variable from class . it works well when i select fields from single table.. when i join query from >1 table then returns error [Exception Details: System.IndexOutOfRangeException: ] see below is the class code: 

    Public Function getUserName(ByRef brID As VariantType, ByRef actType As String, ByRef actNo As VariantType) As SqlDataReader

    sqlstr = "select t1.*,t2.username as [createdby] from [gesactivities] t1 inner join [gesUserlist] t2 on t1.createdbyid=t2.recid where brid=" & brID & " and doctype='" & actType & "' and actnoint=" & actNo

    con = getConnectionObject()
    If con.State = ConnectionState.Open Then
    sqlcmd = New SqlCommand(sqlstr, con)
    sqldr = sqlcmd.ExecuteReader()
    Return sqldr
    Else
    Return Nothing
    End If

    End Function

    *calling it from asp page**********************

    gesBus = New atqBusinessClass("remoteDB")
    sqldr = gesBus.getShipmentInfo(brID, actType, actNo)
    If sqldr.HasRows() Then

          lblCreatedBy.Text = "Job handled by :" & sqldr("createdby").ToString()   '/*field from table 2 see above query*/

    *Returns Error - 

    createdby

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

    Exception Details: System.IndexOutOfRangeException: createdby

    any idea...

    Thanks

    Monday, May 12, 2014 11:10 AM

Answers

  • User753101303 posted

    Hi,

    Could it be that you don't call the proper method ? You are showing us a getUserName function but then you call gesBus.getShipmentInfo. What if using gesBus.getUserName instead ? Depending on another error you may have, you may have to call sqldr.Read() first to get at the first line.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 12, 2014 11:20 AM

All replies

  • User753101303 posted

    Hi,

    Could it be that you don't call the proper method ? You are showing us a getUserName function but then you call gesBus.getShipmentInfo. What if using gesBus.getUserName instead ? Depending on another error you may have, you may have to call sqldr.Read() first to get at the first line.

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, May 12, 2014 11:20 AM
  • User1728944201 posted

    Have you tried the query in SSMS?

    It doesn't look right to me to be joing inner t1.createdbyid to t2.recid 

    Monday, May 12, 2014 1:44 PM
  • User669796193 posted

    thanks PS. was calling wrong method... 

    Tuesday, May 13, 2014 1:56 AM