473,407 Members | 2,326 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.

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 1158
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
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.