RE: Help with DataTable.Rows Reference
- From: "Steve Goodyear" <SteveGoodyear@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 5 Apr 2005 16:49:01 -0700
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.
.
- References:
- Help with DataTable.Rows Reference
- From: MrMike
- Help with DataTable.Rows Reference
- Prev by Date: Re: My first impressions of ASP.NET
- Next by Date: Need to detect if a network path is Novell Netware
- Previous by thread: Help with DataTable.Rows Reference
- Next by thread: Error using Crystal reports in MySQL
- Index(es):
Relevant Pages
|