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).R ows(0).Ite m("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.IndexOutOfRangeExce ption: 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).R ows(0).Ite m("CustID" )
Line 177: connection.Close()
Line 178: End Using
Source File: C:\inetpub\sorder\serviceo rder.aspx. vb Line: 176
Stack Trace:
[IndexOutOfRangeException: There is no row at position 0.]
System.Data.RBTree`1.GetNo deByIndex( Int32 userIndex) +2545949
System.Data.RBTree`1.get_I tem(Int32 index) +16
System.Data.DataRowCollect ion.get_It em(Int32 index) +16
ServiceOrder.getCustomerID () in C:\inetpub\sorder\serviceo rder.aspx. vb:176
ServiceOrder.insertCompute r() in C:\inetpub\sorder\serviceo rder.aspx. vb:252
ServiceOrder.btnSubmit_Cli ck() in C:\inetpub\sorder\serviceo rder.aspx. vb:360
ServiceOrder._Lambda$__3(O bject a0, EventArgs a1) in C:\Windows\Microsoft.NET\F ramework64 \v2.0.5072 7\Temporar y ASP.NET Files\root\7c866b57\59c1fa 31\App_Web _xlgzmri2. 2.vb:0
System.Web.UI.WebControls. Button.OnC lick(Event Args e) +115
System.Web.UI.WebControls. Button.Rai sePostBack Event(Stri ng eventArgument) +140
System.Web.UI.Page.RaisePo stBackEven t(IPostBac kEventHand ler sourceControl, String eventArgument) +29
System.Web.UI.Page.Process RequestMai n(Boolean includeStagesBeforeAsyncPo int, Boolean includeStagesAfterAsyncPoi nt) +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.SqlP arameter
last = New System.Data.SqlClient.SqlP arameter()
last.ParameterName = "@LName"
last.DbType = Data.DbType.String
last.Value = txtLname.Text
command.Parameters.Add(fir st)
command.Parameters.Add(las t)
'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).R ows(0).Ite m("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?
The following code:
custID = myDataSet.Tables.Item(0).R
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.IndexOutOfRangeExce
Source Error:
Line 174: Dim myAdapter As New SqlDataAdapter(command)
Line 175: myAdapter.Fill(myDataSet)
Line 176: custID = myDataSet.Tables.Item(0).R
Line 177: connection.Close()
Line 178: End Using
Source File: C:\inetpub\sorder\serviceo
Stack Trace:
[IndexOutOfRangeException:
System.Data.RBTree`1.GetNo
System.Data.RBTree`1.get_I
System.Data.DataRowCollect
ServiceOrder.getCustomerID
ServiceOrder.insertCompute
ServiceOrder.btnSubmit_Cli
ServiceOrder._Lambda$__3(O
System.Web.UI.WebControls.
System.Web.UI.WebControls.
System.Web.UI.Page.RaisePo
System.Web.UI.Page.Process
--------------------------
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.SqlP
last = New System.Data.SqlClient.SqlP
last.ParameterName = "@LName"
last.DbType = Data.DbType.String
last.Value = txtLname.Text
command.Parameters.Add(fir
command.Parameters.Add(las
'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).R
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?
ASKER
There is almost 800 rows of data.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I would change it to following
If myDataSet.Tables(0).Rows.C
custID = myDataSet.Tables(0).Rows(0
End If