473,385 Members | 1,641 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,385 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 2409
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...
1
by: yanwan | last post by:
I met this problem in executing a c++ project in visual studio. Does anyone have suggestions to resolve "error lnk 2001"? --------------------Configuration: reconstruction - Win32...
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: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...

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.