473,396 Members | 1,972 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,396 software developers and data experts.

Help with DataTable.Rows Reference

Hi. I have a Public Function which requires 2 parameters as follows...
Public Function Test(ByVal 1 as String, ByVal 2 as String)
Prior to calling this function, I fill a dataset(ds) with an undetermined
amount of records, and then use a datatable(dt) to reference the rows of the
datatset.

Dim ds as New DataSet
'Fill DataSet
dt = ds.Tables("Table")

Test(dt.Rows(i)(0), dt.Rows(i + 1)(0))

As you can see the first and second rows from the dataset are passed to the
function. I am having a problem whenever only 1 record exists in the
dataset. When only 1 record exists I get the error message "There is no row
at position 2". Is it possible to send an empty string("") to the function in
order for the function to still run? Or, is there a better way to prevent
this error? Thanks.
Jul 21 '05 #1
1 1156
Hi,
If your "Test" function would still work with an empty string then you can
just test if there is another row and if so use that value, otherwise use the
empty string. Something like:

Dim value1 As String = ""
Dim value2 As String = ""
If dt.Rows.Count > i Then
value1 = dt.Rows(i) (0)
If dt.Rows.Count > i + 1 Then
value2 = dt.Rows(i + 1) (0)
Test (value1, value2)

This way you won't run into an out-of-bounds type of error by trying to
access a row which doesn't exist.

Cheers,
Steve

"MrMike" wrote:
Hi. I have a Public Function which requires 2 parameters as follows...
Public Function Test(ByVal 1 as String, ByVal 2 as String)
Prior to calling this function, I fill a dataset(ds) with an undetermined
amount of records, and then use a datatable(dt) to reference the rows of the
datatset.

Dim ds as New DataSet
'Fill DataSet
dt = ds.Tables("Table")

Test(dt.Rows(i)(0), dt.Rows(i + 1)(0))

As you can see the first and second rows from the dataset are passed to the
function. I am having a problem whenever only 1 record exists in the
dataset. When only 1 record exists I get the error message "There is no row
at position 2". Is it possible to send an empty string("") to the function in
order for the function to still run? Or, is there a better way to prevent
this error? Thanks.

Jul 21 '05 #2

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

Similar topics

8
by: Tim::.. | last post by:
Can someone please tell me why I keep getting the following error for some of my web application users but not others??? Even though the application runs from a central webserver??? Thanks for...
7
by: NEWS | last post by:
I want to display data in a VB.NET DataGrid - but the data is from my VB code, not bound to a database. I am using code like this :- DataGrid1.Item(1, 1) = "Test" I keep getting the message...
11
by: inpuarg | last post by:
I have 2 datatables. They are identical. I want to compare them by cell's content. They are all same. But dt1 == dt2 or dt1.GetHashCode() == dt2.GetHashCode() doesn 't work. There are big...
9
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
I've got a routine that builds a table using different queries, different SQL Tables, and adding custom fields. It takes a while to run (20 - 45 seconds) so I wrote a thread to handle the table...
2
by: yeshello54 | last post by:
so here is my problem...in a contact manager i am trying to complete i have ran into an error..we have lots of code because we have some from class which we can use...anyways i keep getting an error...
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?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
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.