473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

SystemIndexOutOfRangeException error

I'm drawing data from xml file, putting it into datarows, from
datatable subroutine (UseXMLDocument) , and I'm getting a
"System.IndexOutOfRangeException: There is no row at position 0" at the
" Data.Append(dtaData.Rows(0)("Name") & "<BR>") " line.
''''''''''''''
<%@ Page Language="VB" debug="true"%>

<SCRIPT LANGUAGE=VB RUNAT=SERVER>
Private dtaData As DataTable = New DataTable()

Private ID As String
Private Name As String
Private NewDataRow As DataRow
Private ItemsOnlineDataURL As String

Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
Dim PreviousCategory As String = Nothing
Dim Data As StringBuilder = New StringBuilder()
Dim SalesRepID As String = Request.QueryString("SID")
Dim PurchaseLink As String =
"http://www.shoppe.com/ItemsOnline/Purchase.aspx?"
Dim Spacer As String = "<IMG SRC=spacer.gif>"

ItemsOnlineDataURL =
"http://www.shoppe.com/ItemsOnline/Data/salesrep1.xml"

Try
dtaData.Columns.Add("ID")
dtaData.Columns.Add("Name")
dtaData.Columns.Add("PurchaseID")
dtaData.Columns.Add("PkgName")
dtaData.Columns.Add("SelectBlurb")
dtaData.Columns.Add("PkgAmount")
dtaData.Columns.Add("PkgPhone")
dtaData.Columns.Add("DailyItem")
dtaData.Columns.Add("Custom")
dtaData.Columns.Add("WeeklyAmount")
dtaData.Columns.Add("MonthlyAmount")
dtaData.Columns.Add("Category")

UseXmlDocument()
Data.Append(dtaData.Rows(0)("Name") & "<BR>")

Dim drwData As DataRow
For Each drwData In dtaData.Rows
Dim SID As String = "SID=" & Convert.ToString(drwData("ID")) & "&"
Dim PurchaseTypeID As String =
Convert.ToString(drwData("PurchaseID"))
Dim PkgAmount As String =
FormatAmount(Convert.ToSingle(drwData("PkgAmount") ))
Dim PkgPhone As String = Convert.ToString(drwData("PkgPhone"))
Dim PurchaseType As String =
(Convert.ToString(drwData("DailyItem")) )
''''''''''''

.....more coding can be provided if someone can in fact help decipher
why I'm getting the error.

TIA
netsports

Jan 25 '06 #1
4 967
KJ
Hi netsports,

Since dtaData is a newly created table, it has no rows yet. Therefore,
you cannot access dtaData.Rows(0), since it does not exist. To add rows
to a new table, use the NewRow() method of DataTable to create a row.
Then, set the values of the fields of that new row. Finally, call
dtaData.Rows.Add(yourNewRowObject).

Hope this helps.

-KJ

Jan 25 '06 #2
KJ, thanks for the reply -
I have declared dtaData , and I thought I have declared a new row in
the declarations below (and in my code above):
'''''''''''''''
Private dtaData As DataTable = New DataTable()
Private ID As String
Private Name As String
Private NewDataRow As DataRow
''''''''''''''''''
netsports

Jan 25 '06 #3
KJ
The code:

Data.Append(dtaData.Rows(0)("Name") & "<BR>")

fails because dtaData.Rows has no rows in it (dtaData.Rows(0) =
Nothing).

So, before this line, assign a value to NewDataRow using the NewRow()
method, for example:

'assign:
NewDataRow = dtaData.NewRow()

'then set a value:

NewDataRow("Name") = "foo"

'finally, assign the row to your table's Rows collection:
dtaData.Rows.Add(NewDataRow)

'then you can do (no error) because Rows(0) is no longer Nothing:
Data.Append(dtaData.Rows(0)("Name") & "<BR>")

Give this a try and tell me what happens.

Jan 25 '06 #4
Yeah, KJ, I think that does the trick (at least for now, as I have
encountered a different error downstream) .
I had to use the ConvertC# toVB.NET program since the initial code was
in C# , so it probably didnt do a true 100% conversion.
Thanks again
netsports

Jan 25 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
1
by: Aravind | last post by:
we have two files: 1. rc4.c (defines one function "create_pin()") 2. MyImpl.c(calling the function "create_pin()"),This implements JNI method. 1.When I am trying to create .dll file with one...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
6
by: hazz | last post by:
My runtime in debug is dropping through the constructors from an upper level class into subclassed constructors..... namespace AB public class A : MarshalByRefObject public A () ...
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
4
by: .Net Sports | last post by:
I'm drawing data from xml file, putting it into datarows, from datatable subroutine (UseXMLDocument) , and I'm getting a "System.IndexOutOfRangeException: There is no row at position 0" at the "...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.