By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,473 Members | 3,229 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,473 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
%>

Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
<6.**********@spamgourmet.com> 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
%>


Nov 18 '05 #2

P: n/a
On Wed, 23 Jun 2004 17:45:18 +0100, Zenobia
<6.**********@spamgourmet.com> 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
%>


Nov 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.