Z
Zenobia
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
%>
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
%>