Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataView Find method - Error: Expecting 2 value(s) for the key being indexed, but received 3 value(s)

Reply
Thread Tools

DataView Find method - Error: Expecting 2 value(s) for the key being indexed, but received 3 value(s)

 
 
Zenobia
Guest
Posts: n/a
 
      06-23-2004
Hi,

Below is a bit of code from ASP.NET Unleashed which gives an
error and I can't figure out why. It uses the Authors table from
the standard Pubs database.

The error message is
"System.ArgumentException: Expecting 2 value(s) for the
key being indexed, but received 3 value(s)."

For the line:
intRowIndex = dvwAuthors.Find( arrValues )

Can someone, please, explain what is wrong here.

Commenting out one of
arrValues( 0 ) = "Dull"
or
arrValues( 1 ) = "Ann"
seems to makes no difference to the error message.

++++++++++ ++++++++++ ++++++++++

<%@ Page Language="VB" Debug="True" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<%
Dim dstAuthors As DataSet
Dim conPubs As SqlConnection
Dim dadAuthors As SqlDataAdapter
Dim dvwAuthors As DataView
Dim arrValues(2) As Object
Dim intRowIndex As Integer

' Grab Authors Table
dstAuthors = New DataSet()
conPubs = New SqlConnection(
"Server=localhost;UID=sa;PWD=secret;Database=P ubs" )
dadAuthors = New SqlDataAdapter( "Select * From Authors",
conPubs )
dadAuthors.Fill( dstAuthors, "Authors" )

' Create DataView
dvwAuthors = dstAuthors.Tables( "Authors" ).DefaultView()
dvwAuthors.Sort = "au_lname, au_fname"

' Find Ann Dull
arrValues( 0 ) = "Dull"
arrValues( 1 ) = "Ann"
intRowIndex = dvwAuthors.Find( arrValues )

' Display Phone Number
If intRowIndex <> -1 Then
Response.Write( dvwAuthors( intRowIndex ).Row( "Phone" ) )
Else
Response.Write( "Can't find Ann Dull" )
End If
%>

 
Reply With Quote
 
 
 
 
Zenobia
Guest
Posts: n/a
 
      06-23-2004
I replaced these 3 lines:

arrValues( 0 ) = "Dull"
arrValues( 1 ) = "Ann"
intRowIndex = dvwAuthors.Find( arrValues )

with this one and it works now.

dvwAuthors.RowFilter = "au_lname='Dull' and au_fname='Ann'"

was that the 'corrent' thing to do?

But it still doesn't explain the Find error. How do I code the
Find correctly?


On Wed, 23 Jun 2004 17:45:18 +0100, Zenobia
<(E-Mail Removed)> wrote:

>Hi,
>
>Below is a bit of code from ASP.NET Unleashed which gives an
>error and I can't figure out why. It uses the Authors table from
>the standard Pubs database.
>
>The error message is
> "System.ArgumentException: Expecting 2 value(s) for the
>key being indexed, but received 3 value(s)."
>
>For the line:
> intRowIndex = dvwAuthors.Find( arrValues )
>
>Can someone, please, explain what is wrong here.
>
>Commenting out one of
> arrValues( 0 ) = "Dull"
>or
> arrValues( 1 ) = "Ann"
>seems to makes no difference to the error message.
>
> ++++++++++ ++++++++++ ++++++++++
>
><%@ Page Language="VB" Debug="True" %>
><%@ Import Namespace="System.Data" %>
><%@ Import Namespace="System.Data.SqlClient" %>
>
><%
>Dim dstAuthors As DataSet
>Dim conPubs As SqlConnection
>Dim dadAuthors As SqlDataAdapter
>Dim dvwAuthors As DataView
>Dim arrValues(2) As Object
>Dim intRowIndex As Integer
>
>' Grab Authors Table
>dstAuthors = New DataSet()
>conPubs = New SqlConnection(
>"Server=localhost;UID=sa;PWD=secret;Database=Pubs " )
>dadAuthors = New SqlDataAdapter( "Select * From Authors",
>conPubs )
>dadAuthors.Fill( dstAuthors, "Authors" )
>
>' Create DataView
>dvwAuthors = dstAuthors.Tables( "Authors" ).DefaultView()
>dvwAuthors.Sort = "au_lname, au_fname"
>
>' Find Ann Dull
>arrValues( 0 ) = "Dull"
>arrValues( 1 ) = "Ann"
>intRowIndex = dvwAuthors.Find( arrValues )
>
>' Display Phone Number
>If intRowIndex <> -1 Then
> Response.Write( dvwAuthors( intRowIndex ).Row( "Phone" ) )
>Else
> Response.Write( "Can't find Ann Dull" )
>End If
>%>


 
Reply With Quote
 
 
 
 
Zenobia
Guest
Posts: n/a
 
      06-23-2004
On Wed, 23 Jun 2004 17:45:18 +0100, Zenobia
<(E-Mail Removed)> wrote:

Apologies for wasting people's time the book has an error in it.

It should be:
Dim arrValues(1) As Object
not:
Dim arrValues(2) As Object
as, of course, the lower array bound starts at 0.

>Hi,
>
>Below is a bit of code from ASP.NET Unleashed which gives an
>error and I can't figure out why. It uses the Authors table from
>the standard Pubs database.
>
>The error message is
> "System.ArgumentException: Expecting 2 value(s) for the
>key being indexed, but received 3 value(s)."
>
>For the line:
> intRowIndex = dvwAuthors.Find( arrValues )
>
>Can someone, please, explain what is wrong here.
>
>Commenting out one of
> arrValues( 0 ) = "Dull"
>or
> arrValues( 1 ) = "Ann"
>seems to makes no difference to the error message.
>
> ++++++++++ ++++++++++ ++++++++++
>
><%@ Page Language="VB" Debug="True" %>
><%@ Import Namespace="System.Data" %>
><%@ Import Namespace="System.Data.SqlClient" %>
>
><%
>Dim dstAuthors As DataSet
>Dim conPubs As SqlConnection
>Dim dadAuthors As SqlDataAdapter
>Dim dvwAuthors As DataView
>Dim arrValues(2) As Object
>Dim intRowIndex As Integer
>
>' Grab Authors Table
>dstAuthors = New DataSet()
>conPubs = New SqlConnection(
>"Server=localhost;UID=sa;PWD=secret;Database=Pubs " )
>dadAuthors = New SqlDataAdapter( "Select * From Authors",
>conPubs )
>dadAuthors.Fill( dstAuthors, "Authors" )
>
>' Create DataView
>dvwAuthors = dstAuthors.Tables( "Authors" ).DefaultView()
>dvwAuthors.Sort = "au_lname, au_fname"
>
>' Find Ann Dull
>arrValues( 0 ) = "Dull"
>arrValues( 1 ) = "Ann"
>intRowIndex = dvwAuthors.Find( arrValues )
>
>' Display Phone Number
>If intRowIndex <> -1 Then
> Response.Write( dvwAuthors( intRowIndex ).Row( "Phone" ) )
>Else
> Response.Write( "Can't find Ann Dull" )
>End If
>%>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorted DataView, but unsorted datalist when bound to the dataview CodeMonkey ASP .Net 1 02-04-2011 10:55 AM
java.lang.VerifyError: Expecting to find object/array on stack pcouas Java 13 02-20-2006 04:39 PM
nuby: determine method passed and determine the receiver that received the method Peņa, Botp Ruby 1 01-24-2004 07:51 PM
I received an autoreply for being over quota but cant stop the spam Andy Starnes Computer Support 4 12-12-2003 09:14 PM
HELP from Expert Needed!!! Problem using the find method in a DataView with multiple window forms miggy ASP .Net 2 11-15-2003 10:03 AM



Advertisments