473,378 Members | 1,104 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,378 software developers and data experts.

table.rows.find problem

The following code never finds a matching row even when one exists. It
appears that the method thinks there is only one value being passed to the
method even though the object array that is passed has 2 elements, and both
elements have values.

Any ideas?

if ((dsReturned.Tables.Count > 0) && (dsReturned.Tables[0].Rows.Count > 0))
{
object[] objKeys = new object[2];
DataRow drFound;

foreach (DataRow dr in dsReturned.Tables[0].Rows)
{
objKeys[0] = dr["ItemID"]; // String
objKeys[1] = dr["ItemTrackDateTime"]; // DateTime
drFound = dsItemTracks.Tables[0].Rows.Find(objKeys);

if (drFound != null)
{
drFound.Delete();
}
}
}
May 10 '06 #1
6 10375
Hi,

Make sure that the searched table ( dsItemTracks.Tables[0] ) define the
primary keys in the same order.

Alternatively you can iterate the table manually and see what happens when
the expected row is found.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Derek" <De***@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
The following code never finds a matching row even when one exists. It
appears that the method thinks there is only one value being passed to the
method even though the object array that is passed has 2 elements, and
both
elements have values.

Any ideas?

if ((dsReturned.Tables.Count > 0) && (dsReturned.Tables[0].Rows.Count >
0))
{
object[] objKeys = new object[2];
DataRow drFound;

foreach (DataRow dr in dsReturned.Tables[0].Rows)
{
objKeys[0] = dr["ItemID"]; // String
objKeys[1] = dr["ItemTrackDateTime"]; // DateTime
drFound = dsItemTracks.Tables[0].Rows.Find(objKeys);

if (drFound != null)
{
drFound.Delete();
}
}
}

May 10 '06 #2
Hi,

All keys seem to be defined correctly. When I try to run
"?dsItemTracks.Tables[0].Rows.Find(objKeys)" in the Command Window I get the
following error:
{"Expecting 2 value(s) for the key being indexed, but received 1 value(s)." }
System.SystemException: {"Expecting 2 value(s) for the key being
indexed, but received 1 value(s)."}
m_paramName: null
Message: "Expecting 2 value(s) for the key being indexed, but received 1
value(s)."
ParamName: null

I'm not sure if this is caused by running it in the CW or if it is the
underlying cause in the code.

I checked all keys, and the object array and everything seems in order.
May 10 '06 #3
PS:

I believe there is a way to declare the key values (not just a single key
value) directly in the Find method.

e.g. drFound = dsItemTracks.Tables[0].Rows.Find("Something in here");

Is there an example of this I could see?
May 10 '06 #4
Hi,

"Derek" <De***@discussions.microsoft.com> wrote in message
news:E1**********************************@microsof t.com...
PS:

I believe there is a way to declare the key values (not just a single key
value) directly in the Find method.

e.g. drFound = dsItemTracks.Tables[0].Rows.Find("Something in here");


you can do

drs Found = dsItemTracks.Tables[0].Rows.Find( new object[] { 'key1',
DateTime.Now } );
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
May 10 '06 #5
Derek,
In addition to the other comments. Remember that Dates have times associated
with them.

Are you certain that both tables have the same values date & time in the
DateTime column? To the same precision...

FWIW: I would consider setting up a DataRelation between the two tables,
them simply use the children of the relationship (via DataRow.GetChildRows)
rather then using Rows.Find...

--
Hope this helps
Jay B. Harlow [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net
"Derek" <De***@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
| The following code never finds a matching row even when one exists. It
| appears that the method thinks there is only one value being passed to the
| method even though the object array that is passed has 2 elements, and
both
| elements have values.
|
| Any ideas?
|
| if ((dsReturned.Tables.Count > 0) && (dsReturned.Tables[0].Rows.Count >
0))
| {
| object[] objKeys = new object[2];
| DataRow drFound;
|
| foreach (DataRow dr in dsReturned.Tables[0].Rows)
| {
| objKeys[0] = dr["ItemID"]; // String
| objKeys[1] = dr["ItemTrackDateTime"]; // DateTime
| drFound = dsItemTracks.Tables[0].Rows.Find(objKeys);
|
| if (drFound != null)
| {
| drFound.Delete();
| }
| }
| }
May 11 '06 #6
Thanks for the info guys. This problem is intriguing me. I think the problem
lies in:

dsItemTracks.Tables[0].Rows.Find(objKeys);

When I put a watch on this, I get a value of:

{"Expecting 2 value(s) for the key being indexed, but received 1 value(s)." }

There are definately 2 key columns defined in dsItemTracks, and objKeys is
positively an array of objects with 2 elements in the same order, and of the
same types as the keys for the table.
May 11 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Raaijmakers, Vincent (IndSys, GE Interlogix) | last post by:
Ok, perhaps a question on a newbie level. I try to create a simple 'write to a console application' where all the items in a string do have a variable size: items = Well, actually, I need to...
2
by: G.W. Lucas | last post by:
I apologize if this is a RTFM question, but I have not been able to find a definitive answer elsewhere. Does a "REINDEX TABLE" lock the table while it is working? Can applications write data to...
6
by: Fan Ruo Xin | last post by:
I try to copy a table from production system (DB2 UDB EEE V7.2 + fixpak5) to the testing system (DB2 UDB V8.1 + fixpak4a). I moved the data from productions system by using the following steps:...
2
by: Joe | last post by:
Hi All, I am new to using the Access DB and I need some help if someone is able to give it to me. What I want to do is get the names of the columns of certain tables. Not the data in the table...
6
by: Roy Gourgi | last post by:
Hi, I am trying to add a row to my table but I get the error message "invalid column name SOBN and BN1" on this statement. Basically, I am trying to add the row into the same table that I am...
0
by: Luis Esteban Valencia | last post by:
Hello I wrote a program with code behind in C# to add row into table dynamically and the program worked very well in .Net Framework 1.1. When I run this program in .Net Framework 2.0 beta...
33
by: Geoff Jones | last post by:
Hiya I have a DataTable containing thousands of records. Each record has a primary key field called "ID" and another field called "PRODUCT" I want to retrieve the rows that satisy the following...
1
by: Fix_Metal | last post by:
Hello all. I'm new to this group :) I have a problem with javascript language. I'm making an .asp page with some integrated Javascript functions. The page consists of some HTML selects and a...
7
by: Kamal | last post by:
Hello all, I have a very simple html table with collapsible rows and sorting capabilities. The collapsible row is hidden with css rule (display:none). When one clicks in the left of the...
6
by: google | last post by:
I am having trouble with the following function that I am modifying from www.isocra.com. I am trying to change the ID of a hidden form object inside a table row. I have used alert() to test where...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.