Link to home
Start Free TrialLog in
Avatar of computrex
computrex

asked on

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

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?
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of computrex
computrex

ASKER

There is almost 800 rows of data.
ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial