473,395 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Error in finding a value with a composed key

Hello,

I'm new to C#, and i need help with the following problem:

I have a DataTable called 'Nomes', part of a DataSet with various datatables.
I am searching a record (that i know it exists) in that DataTable. I need two fields from that DataTable to compose the key.
Example: i'm looking for the record where field 'Codigo' = '000100' and field 'CPostal' = '3000-001'.

Expand|Select|Wrap|Line Numbers
  1. // Defining fields 'codigo' + 'cpostal' as key fields
  2. Nomes.PrimaryKey = new DataColumn[] {Nomes.Columns["codigo"], Nomes.Columns["cpostal"]} ;
  3.  
  4. // Defining values to locate
  5. object Chave = new object[] { "000100", "3000-001" };
  6.  
  7. // Using object 'Chave' search the record where codigo = "000100" and cpostal = "3000-001"
  8. DataRow RegistoEncontrado = Nomes.Rows.Find(Chave);
  9.  
But when this last row of code runs i get the following error:
"Expecting 2 value(s) for the key being indexed, but received 1 value(s)."

I think this error message don't make much sense, because the parameter send to the find() method was an object with 2 values.

Does anybody knows what have i done wrong?

TIA,
Joaquim
Mar 31 '07 #1
1 1533
Sorry to everyone,

You don't have to answer, it was a rookie error: i forgot the '[]' when creating the object 'chave'.

Thank you,
Joaquim

Hello,

I'm new to C#, and i need help with the following problem:

I have a DataTable called 'Nomes', part of a DataSet with various datatables.
I am searching a record (that i know it exists) in that DataTable. I need two fields from that DataTable to compose the key.
Example: i'm looking for the record where field 'Codigo' = '000100' and field 'CPostal' = '3000-001'.

Expand|Select|Wrap|Line Numbers
  1. // Defining fields 'codigo' + 'cpostal' as key fields
  2. Nomes.PrimaryKey = new DataColumn[] {Nomes.Columns["codigo"], Nomes.Columns["cpostal"]} ;
  3.  
  4. // Defining values to locate
  5. object Chave[] = new object[] { "000100", "3000-001" };
  6.  
  7. // Using object 'Chave' search the record where codigo = "000100" and cpostal = "3000-001"
  8. DataRow RegistoEncontrado = Nomes.Rows.Find(Chave);
  9.  
But when this last row of code runs i get the following error:
"Expecting 2 value(s) for the key being indexed, but received 1 value(s)."

I think this error message don't make much sense, because the parameter send to the find() method was an object with 2 values.

Does anybody knows what have i done wrong?

TIA,
Joaquim
Mar 31 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Amir | last post by:
Hi all, I have a table called PTRANS with few columns (see create script below). I have created a view on top that this table VwTransaction (See below) I can now run this query without a...
3
by: Michael | last post by:
Hello again everyone, Hope you can help. I have a form with a lot of code going on in the background but I can't find the route cause of the following error message. Update or Cancel Update...
38
by: Red Dragon | last post by:
I am self study C student. I got stuck in the program below on quadratic equation and will be most grateful if someone could help me to unravel the mystery. Why does the computer refuse to execute...
3
by: Stephen Miller | last post by:
I have an ASP.Net application that sends a NetworkStream to a .Net Service, which has a TcpListener listening on a port for the ASP.Net client. When it receives a request it creates a new thread...
13
by: dbuchanan | last post by:
Hello, Here is the error message; ---------------------------- Exception Message: ForeignKeyConstraint Lkp_tbl040Cmpt_lkp302SensorType requires the child key values (5) to exist in the...
3
by: Guy Debord | last post by:
Hello all, I know that this is a long shot, but I have a problem which someone reading this group *may* just be able to shed some light on. We have a new internal personnel planner/attendance...
13
by: problem. | last post by:
#include <stdio.h> #include <stdlib.h> int main(void) { int a, b; float result = 0.0f; char symbol = '\0'; int loop = 0;
1
by: =?ISO-8859-1?Q?Lasse_V=E5gs=E6ther_Karlsen?= | last post by:
I get the above error in some of the ASP.NET web applications on a server, and I need some help figuring out how to deal with it. This is a rather long post, and I hope I have enough details that...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.