RE: Help with DataTable.Rows Reference

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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.
.



Relevant Pages

  • Re: $_REQUEST
    ... Calling the first URL everything works fine, calling the second I get an ... error saying 'VAR2' is not in the array $_REQUEST. ... want my function to return an empty string. ... > Kind Regards ...
    (alt.php)
  • Re: [Global.asax] function Server.MapPath not available ?
    ... you are implicitly calling the method or accessing the property from the Page object. ... Instead of calling the MapPath method, you can call the Context.MapPath method. ... my .aspx page folder is here ... both return an empty string ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Is this recursion?
    ... In the simplified example code I provided, the empty string does not ... I understand that calling a recursive method when a negative ... I do check for the empty string condition before ...
    (comp.lang.java.help)
  • VB6 empty string -> to a .net - how to
    ... How does one send an empty string from vb6 when calling a vb.net function through interop? ...
    (microsoft.public.dotnet.framework.interop)