Solved

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

Posted on 2013-05-16
3
711 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
datetime in sql 6 24
T-SQL:  I Want "Summary"--Not "Detail" 6 20
Variable Event ? 3 22
Need a starter for ETL protocol? 4 39
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 …
Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

911 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

18 Experts available now in Live!

Get 1:1 Help Now