Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-05-16
3
Medium Priority
?
769 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 total points
ID: 39174415
Matching the LName and FName? Obviously its not being populated in the dataset hence the error.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In part one, we reviewed the prerequisites required for installing SQL Server vNext. In this part we will explore how to install Microsoft's SQL Server on Ubuntu 16.04.
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

636 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