Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DataView.Find error: Expecting 2 value(s) for the key being indexed, but received 1 value(s).

2 views
Skip to first unread message

Benjamin Joldersma

unread,
Oct 8, 2003, 9:36:25 PM10/8/03
to
Hello all,

I've searched the forum for this error, but there are only two posts
on the topic. We are seeing something very strange happening. We
have a DataView with a Sort property specified to a two column
expression:

DataView dv = new DataView( sourcetable );
dv.Sort = "ContentTypeId,ContentId";

//then we create our search array:

object[] searchKeys = new object[2]{ 9, 2 };

//and run our search:

if( dv.Find( searchKeys ) > -1 )
{
....
}

//never gets inside the if loop, error:
Expecting 2 value(s) for the key being indexed, but received 1
value(s).

but the really interesting thing is that if we change the sort key in
the command window to a single key, and pass in the same array, we get
the opposite error:

dv.Sort = "ContentTypeId";
if( dv.Find( searchKeys ) > -1 )
{
...
}

we get this error:
Expecting 1 value(s) for the key being indexed, but received 2
value(s).

Can anyone shed any light on this topic? We are using a DefaultView
on a datatable, and it is a static member of our class in an ASP.NET
HttpModule ocntext.

thanks in advance!

Benjamin Joldersma
Sr. Software Engineer,
Citadel Media, Inc.

Kevin Sun [MS]

unread,
Oct 9, 2003, 3:05:49 AM10/9/03
to
Please check the following line of code about the define of the searchkey

object[] searchKeys = new object[2]{ 9, 2 };

The following is a simple VB.NET sample:

=============
Private Sub FindValueInDataView(t As DataTable)
Dim dv As DataView
Dim i As Integer
Dim vals(1) As Object
dv = New DataView(t)
dv.Sort = "Cusomers"
' Find the customer named "John Smith".
vals(0)= "John"
vals(1) = "Smith"
i = dv.Find(vals)
Console.WriteLine(dv(i))
End Sub
=============

Sincerely,

Kevin
Microsoft Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! - www.microsoft.com/security

--------------------
| From: be...@theinsiders.com (Benjamin Joldersma)
| Newsgroups: microsoft.public.dotnet.framework.adonet
| Subject: DataView.Find error: Expecting 2 value(s) for the key being

indexed, but received 1 value(s).

| Date: 8 Oct 2003 18:36:25 -0700
| Organization: http://groups.google.com
| Lines: 48
| Message-ID: <8fd02140.03100...@posting.google.com>
| NNTP-Posting-Host: 65.101.136.67
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit
| X-Trace: posting.google.com 1065663385 15604 127.0.0.1 (9 Oct 2003
01:36:25 GMT)
| X-Complaints-To: groups...@google.com
| NNTP-Posting-Date: Thu, 9 Oct 2003 01:36:25 +0000 (UTC)
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!newsfeed00.sul.t-online.de!t-onlin
e.de!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out1.nntp.be!propa
gator2-sterling!In.nntp.be!tdsnet-transit!newspeer.tds.net!sn-xit-02!sn-xit-
04!sn-xit-06!sn-xit-09!supernews.com!postnews1.google.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:63262
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet

Benjamin Joldersma

unread,
Oct 9, 2003, 1:58:32 PM10/9/03
to
Kevin,

Thank you for the expedient response. Unfortunately, the primary
change you suggested, changing:

object[] keys = new object[2]{1,2};

to:

object[] keys = new object[2];
keys[0] = 1;
keys[1] = 2;

continues to produce the same error. I also tried creating a local
DataView inside the method, instead of using the static member. But
again, the error continues. We are using the SqlHelper class to
generate our table. Could this have anything to do with it? We are
able to perform single-column Finds.

Any further insight or suggestions are greatly apprediated. Thanks
again for the help.

Benjamin Joldersma,

Kevin Sun [MS]

unread,
Oct 10, 2003, 5:37:57 AM10/10/03
to
I am trying to reproduce the same problem on my side. If you have a
simplified sample, you could send me.

Sincerely,

Kevin
Microsoft Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! - www.microsoft.com/security

--------------------
| From: be...@theinsiders.com (Benjamin Joldersma)
| Newsgroups: microsoft.public.dotnet.framework.adonet

| Subject: Re: DataView.Find error: Expecting 2 value(s) for the key being

indexed, but received 1 value(s).

| Date: 9 Oct 2003 10:58:32 -0700
| Organization: http://groups.google.com
| Lines: 25
| Message-ID: <8fd02140.03100...@posting.google.com>
| References: <8fd02140.03100...@posting.google.com>
<#cbDPPjj...@cpmsftngxa06.phx.gbl>


| NNTP-Posting-Host: 65.101.136.67
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit

| X-Trace: posting.google.com 1065722312 28394 127.0.0.1 (9 Oct 2003
17:58:32 GMT)
| X-Complaints-To: groups...@google.com
| NNTP-Posting-Date: Thu, 9 Oct 2003 17:58:32 +0000 (UTC)
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.co
m!news.maxwell.syr.edu!postnews1.google.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:63310
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet

Benjamin Joldersma

unread,
Oct 10, 2003, 2:12:54 PM10/10/03
to
Kevin,

here is a simplified version of the class. I've tried to keep some of
the interesting particulars of our situation, such as the SqlHelper,
and the static members, in case that has anything to do with it. We
are calling this from the context of an Application_BeginRequest()
event handler of an HttpModule. Hope you can help!

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Web;
using Microsoft.ApplicationBlocks.Data;

namespace FindTest
{
/// <summary>
/// Stripped down version of our AuthorizationManager to
/// help describe the "Expecting 2 value(s) for the key
/// being indexed, but received 1 value(s)." bug.
/// </summary>
public class AuthorizationManager
{
private static DataView authorizationListView;

/// <summary>
/// Loads the authorization list into a static DataView, starts
/// a timer to periodically ping the database for new definitions.
/// </summary>
static AuthorizationManager()
{
LoadData( null, null );

int interval = 5 * 60 * 1000; //run every 5 minutes
System.Timers.Timer timer = new System.Timers.Timer();
timer.Elapsed+=new System.Timers.ElapsedEventHandler(LoadData);
timer.Interval=interval;
timer.Start();
}

/// <summary>
///up_Authenticate_LIST returns a two column list of integers,
///defining premium documents, like:
///ContentTypeId ContentId
///============= =========
///2 10239
///2 19233
///2 28492
///9 392
/// </summary>
/// <param name="source"></param>
/// <param name="e"></param>
public static void LoadData(object source,
System.Timers.ElapsedEventArgs e)
{
DataSet ds = SqlHelper.ExecuteDataset( TODO: GetConnectionString,
"up_Authenticate_LIST", null );
DataView dv = new DataView( ds.Tables[0] );
dv.Sort = "ContentId, ContentTypeId";
authorizationListView = dv;
}

/// <summary>
/// Returns true if the specified content tuple exists in the
DataTable
/// returned from up_Authenticate_LIST.
/// </summary>
/// <param name="ContentTypeId"></param>
/// <param name="ContentId"></param>
/// <returns></returns>
public static bool DocumentIsPremium( int ContentTypeId, int
ContentId )
{
object[] searchKeys = new object[2];
searchKeys[0] = ContentId;
searchKeys[1] = ContentTypeId;
return ( authorizationListView.Find( searchKeys ) > -1 );
/*
* this is the alternate method we developed,
* using a one column Sort ( "ContentId"), it
* iterates the DataRowView[] collection that is
* returned and manually searches for the second value.
if( authorizationListView != null )
{
foreach( DataRowView drv in authorizationListView.FindRows(
ContentId ) )
{
if( (int)drv["ContentTypeId"] == ContentTypeId )
{
return true;
}
}
}
return false;*/
}
}
}

Kevin Sun [MS]

unread,
Oct 13, 2003, 3:09:14 AM10/13/03
to
Hi,

I tried to build a sample based on the information you provided, and
reproduced the same problem.

After further troubleshooting, I found that it is caused by the order of
the parameters in the keys.

Make sure the parameters in the searchKeys[] are associated with the sort
of the dataview.

392 ->ContentId
9 -> ContentTypeId

dv.Sort = "ContentId, ContentTypeId";
object[] searchKeys = new object[2]{ 392,9 };

The following example works fine on my side:
===================
private void bnTestDateViewFind_Click(object sender, System.EventArgs e)
{
// Initialize the connection string and command text
// These will form the key used to store and retrieve the parameters
const string CONN_STRING = "SERVER=(local); DATABASE=test; INTEGRATED
SECURITY=True;";
string spName = "SELECT * FROM tblDataViewFind";

//Use the parameters in a command
DataSet ds;
ds = SqlHelper.ExecuteDataset(CONN_STRING, CommandType.Text ,spName);



DataView dv = new DataView( ds.Tables[0] );

dv.Sort = "ContentId, ContentTypeId";


object[] searchKeys = new object[2]{ 392,9 };
PrintTableOrView(dv,"test");

int i = dv.Find(searchKeys);
if(i>-1)
{
// ....
Console.Write ("test dataview");

Console.WriteLine("\t" + dv[i]["ContentId"]);
Console.WriteLine("\t" + dv[i]["ContentTypeId"]);
}

}

private void PrintTableOrView(DataView dv, string label)
{

// This overload prints values in the table or DataView.
Console.WriteLine("\n" + label);
for(int i = 0; i<dv.Count;i++)
{
Console.WriteLine("\t" + dv[i]["ContentTypeId"]);

Console.WriteLine("\t" + dv[i]["ContentId"]);

}
Console.WriteLine();
}
===================

Sincerely,

Kevin
Microsoft Support

This posting is provided "AS IS" with no warranties, and confers no rights.
Get Secure! - www.microsoft.com/security

--------------------
| From: be...@theinsiders.com (Benjamin Joldersma)
| Newsgroups: microsoft.public.dotnet.framework.adonet

| Subject: Re: DataView.Find error: Expecting 2 value(s) for the key being

indexed, but received 1 value(s).

| Date: 10 Oct 2003 11:12:54 -0700
| Organization: http://groups.google.com
| Lines: 102
| Message-ID: <8fd02140.03101...@posting.google.com>
| References: <8fd02140.03100...@posting.google.com>
<#cbDPPjj...@cpmsftngxa06.phx.gbl>
<8fd02140.03100...@posting.google.com>
<dScw3Ixj...@cpmsftngxa06.phx.gbl>


| NNTP-Posting-Host: 65.101.136.67
| Content-Type: text/plain; charset=ISO-8859-1
| Content-Transfer-Encoding: 8bit

| X-Trace: posting.google.com 1065809575 30074 127.0.0.1 (10 Oct 2003
18:12:55 GMT)
| X-Complaints-To: groups...@google.com
| NNTP-Posting-Date: Fri, 10 Oct 2003 18:12:55 +0000 (UTC)
| Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!news-out.cwix.com!newsfeed.cwix.co
m!news.maxwell.syr.edu!sn-xit-03!sn-xit-06!sn-xit-09!supernews.com!postnews1
.google.com!not-for-mail
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.framework.adonet:63388
| X-Tomcat-NG: microsoft.public.dotnet.framework.adonet

0 new messages