Avatar of Trancedified
TrancedifiedFlag for United States of America

asked on 

Index 0 is not non-negative and below total rows count.

I'm running this code:

        Dim dvTest As DataView

        Dim cnn As SqlConnection = Utilities.GetMyConnectionString
        Dim cmd As New SqlCommand("mystoredprocedure", cnn)
        Dim dSet As New DataSet

        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandTimeout = 2000

        Dim da As New SqlDataAdapter(cmd)

        Try
            da.Fill(dSet, "Accounts")
            dvTest = dSet.Tables("Accounts").DefaultView
            'Filter by one ID
            dvTest.RowFilter = String.Format("ID='{0}'", (Utilities.PadRight(Me.ID, 15)))

            sb.Append(dvTest.Item(0).Item(2).ToString) 'build into string
            sb.ToString

        Catch ex As Exception
            Throw
        End Try

But I get the error:

Index 0 is not non-negative and below total rows count.

What is strange is that it is that the stored procedure is returning more than 1 record in the dataview, but somewhere it's dieing out.... any ideas?

Chris
Visual Basic.NET

Avatar of undefined
Last Comment
Trancedified
ASKER CERTIFIED SOLUTION
Avatar of ptakja
ptakja
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Trancedified
Trancedified
Flag of United States of America image

ASKER

I just figured it out, I was running a query vs the database and whenever ID's don't match (returning a dvTest.Count = 0) then it gives me that error.

So to avoid after the row filter I put

If dvTest.Count = 1 Then '(there is a match)
'Build string
Else
'Don't build string

End If

I'll give you the points for effort!

Chris
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo