Solved

Move website from iis6 to iis7 (There is no row at position 0. )

Posted on 2013-05-16
3
709 Views
Last Modified: 2013-08-12
Moved a website that uses ASP.Net/Ajax2.0.  The database is MS SQL 2008R2  There has not been any code changes.

The following code:

            custID = myDataSet.Tables.Item(0).Rows(0).Item("CustID")


Is causing the following error:
Server Error in '/' Application.
--------------------------------------------------------------------------------

There is no row at position 0.
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: There is no row at position 0.

Source Error:


Line 174:            Dim myAdapter As New SqlDataAdapter(command)
Line 175:            myAdapter.Fill(myDataSet)
Line 176:            custID = myDataSet.Tables.Item(0).Rows(0).Item("CustID")
Line 177:            connection.Close()
Line 178:        End Using
 

Source File: C:\inetpub\sorder\serviceorder.aspx.vb    Line: 176

Stack Trace:


[IndexOutOfRangeException: There is no row at position 0.]
   System.Data.RBTree`1.GetNodeByIndex(Int32 userIndex) +2545949
   System.Data.RBTree`1.get_Item(Int32 index) +16
   System.Data.DataRowCollection.get_Item(Int32 index) +16
   ServiceOrder.getCustomerID() in C:\inetpub\sorder\serviceorder.aspx.vb:176
   ServiceOrder.insertComputer() in C:\inetpub\sorder\serviceorder.aspx.vb:252
   ServiceOrder.btnSubmit_Click() in C:\inetpub\sorder\serviceorder.aspx.vb:360
   ServiceOrder._Lambda$__3(Object a0, EventArgs a1) in C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files\root\7c866b57\59c1fa31\App_Web_xlgzmri2.2.vb:0
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +115
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +140
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +29
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2981

 --------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4984; ASP.NET Version:2.0.50727.4971

More Details:
Here is the code in context:

Private Function getCustomerID() As Boolean
        Using connection As New SqlConnection(cs)
            'Specify the SQL query
            Const sql As String = "SELECT CustID FROM Customer WHERE FName = @FName AND LName = @LName;"
            Dim command As New SqlCommand(sql, connection)
            Dim first As SqlParameter
            first = New SqlParameter()
            first.ParameterName = "@FName"
            first.DbType = Data.DbType.String
            first.Value = txtFname.Text
            Dim last As System.Data.SqlClient.SqlParameter
            last = New System.Data.SqlClient.SqlParameter()
            last.ParameterName = "@LName"
            last.DbType = Data.DbType.String
            last.Value = txtLname.Text
            command.Parameters.Add(first)
            command.Parameters.Add(last)
            'Get back a DataSet
            Dim myDataSet As New Data.DataSet
            'Create a SqlDataAdapter instance
            Dim myAdapter As New SqlDataAdapter(command)
            myAdapter.Fill(myDataSet)
            custID = myDataSet.Tables.Item(0).Rows(0).Item("CustID")
            connection.Close()
        End Using
        getCustomerID = True
    End Function

Here is the layout of the database:
      [CustID] [int] IDENTITY(1,1) NOT NULL,
      [LName] [varchar](25) NOT NULL,
      [FName] [varchar](25) NOT NULL,
      [Apartment] [varchar](35) NULL,
      [Street] [varchar](35) NOT NULL,
      [City] [varchar](25) NOT NULL,
      [State] [nchar](2) NOT NULL,
      [Zip] [nchar](5) NOT NULL,
      [WorkNo] [nchar](12) NULL,
      [HomeNo] [nchar](12) NULL,
      [CellNo] [nchar](12) NULL,
      [FaxNo] [nchar](12) NULL,
      [Email] [varchar](100) NULL,
      [HeardHow] [varchar](30) NOT NULL,
 CONSTRAINT [PK_Customer] PRIMARY KEY CLUSTERED

Up to the point where we have to submit the form, the rpogram works fine.  Even the main menu.

Any thoughts?
0
Comment
Question by:computrex
  • 2
3 Comments
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 39174373
Nothing to do with IIS. Your data has changed and myDataset.Tables has not rows.

I would change it to following

If myDataSet.Tables(0).Rows.Count > 0 Then
   custID = myDataSet.Tables(0).Rows(0).Item("CustID")
End If
0
 
LVL 5

Author Comment

by:computrex
ID: 39174400
There is almost 800 rows of data.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 39174415
Matching the LName and FName? Obviously its not being populated in the dataset hence the error.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now