Click here to Skip to main content
15,908,166 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi guys can you help me on this one, I'm only having this error when my site is deployed on IIS

C#
Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 

[IndexOutOfRangeException: There is no row at position 0.]    
System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) +1556386    
System.Data.DataRowCollection.get_Item(Int32 index) +20    
HRMS.Index.Page_Load(Object sender, EventArgs e) in 
C:\Users\orculloj\Desktop\New folder (2)\HRMS\HRMS\Index.aspx.vb:83    
System.Web.UI.Control.OnLoad(EventArgs e) +92    
System.Web.UI.Control.LoadRecursive() +54    
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, 
Boolean includeStagesAfterAsyncPoint) +772 


What I have tried:

HERE IS MY PAGE_LOAD CODE:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
  
        Dim DomainUser As String = System.Web.HttpContext.Current.User.Identity.Name.Replace("\", "/")  
        'Dim DomainUser As String = System.Security.Principal.WindowsIdentity.GetCurrent.Name.Replace("\", "/")  
  
        Dim sUser() As String = Split(DomainUser, "/")  
        Dim sUserId As String = ""  
        'Dim sDomain As String = sUser(0)  
        If DomainUser <> "" Then  
            sUserId = sUser(1)  
        End If  
  
        pubUser = sUserId  
  
        'pubUser = "ricerrae"  
  
        userID.Text = pubUser  
  
        'UpdateUserStatusTemp()  
  
        GetEmpInfo()  
        LastLeave()  
        PopulateHolidays(Val(lblMonth.Text))  
  
        If Not Page.IsPostBack Then  
            If dtEmp.Rows.Count > 0 Then  
                employeeID = dtEmp.Rows(0)("EmpID")  
                employeeName = dtEmp.Rows(0)("EmpName")  
                employeeSupervisor = dtEmp.Rows(0)("MngrName")  
                employeeDepartment = dtEmp.Rows(0)("LOBDesc")  
                employeeLocation = dtEmp.Rows(0)("Location")  
                employeeDoj = CDate(dtEmp.Rows(0)("DateJoined")).ToString("MMMM dd, yyyy")  
                employeeApprover = dtEmp.Rows(0)("MngrName")  
  
                empID.Text = employeeID  
                empName.Text = employeeName  
                supervisor.Text = employeeSupervisor  
                dept.Text = employeeDepartment  
                doj.Text = employeeDoj  
                approver.Text = employeeApprover  
            End If  
              
            PopulateHolidays(Today.Month)  
  
            If dtHoliday_reg.Rows.Count > 0 Then  
                lblMonth.Text = Today.Month  
  
                lblLeaveBal.Text = IIf(IsDBNull(dtEmp.Rows(0)("LeaveBal")), "00", dtEmp.Rows(0)("leaveBal"))  
  
            End If  
              
            If dtChkLeave.Rows.Count > 0 Then  
                lblLastLeave.Text = dtChkLeave.Rows(0)("LastLeave")  
            End If  
  
        End If  
    End Sub  
Posted
Updated 3-May-16 20:13pm
Comments
PIEBALDconsult 3-May-16 18:59pm    
Maybe because of:
If dtHoliday_reg.Rows.Count > 0 Then .... IIf(IsDBNull(dtEmp.Rows(0)("LeaveBal")) ... ?
Philippe Mori 3-May-16 21:30pm    
As indicated in above comment, the error is probably that you check wrong table rows count...

Anyway, that kind of problem should be easy to find by using a debugger since you would know on which line the error occurs and you can inspect variables when it crash and see which collection is empty.

Finally, you should also fix the formatting of the above code block. It look like the syntax coloring is wrong starting at the comment. By the way, it is almost pointless to show us commented out code.
Member 11525563 4-May-16 5:15am    
Hi, since im only getting this error when i run it through IIS, i cannot figure out how i can debug this, because when i run the code locally i'm not getting this kind of error.
Philippe Mori 4-May-16 8:16am    
Then use same data locally than remotly and you will probably have same problem locally. If you have remote access to the database, then connect to that database instead of the local one. If nothing works, then modify the code so that you can log or display the information you need.

1 solution

I believe this line is the cause:
VB
lblLeaveBal.Text = IIf(IsDBNull(dtEmp.Rows(0)("LeaveBal")), "00", dtEmp.Rows(0)("leaveBal"))  


because you're using dtEmp.Rows(0) outside of the check that there are in fact dtEmp rows. Move this line within the if block
VB
If dtEmp.Rows.Count > 0 Then  

and the error should go away.

Good luck.
 
Share this answer
 
Comments
Member 11525563 4-May-16 5:12am    
@Sinisa Hajnal thanks ill try that

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900