rows.find with composite key
rows.find with composite key
rows.find with composite key
rows.find with composite key
rows.find with composite key
rows.find with composite key rows.find with composite key rows.find with composite key rows.find with composite key rows.find with composite key rows.find with composite key rows.find with composite key rows.find with composite key
rows.find with composite key rows.find with composite key
rows.find with composite key
Go Back  Xtreme Visual Basic Talk > > > rows.find with composite key


Reply
 
Thread Tools Display Modes
  #1  
Old 06-18-2014, 10:27 PM
PatM PatM is offline
Freshman
 
Join Date: Mar 2006
Posts: 28
Default rows.find with composite key


I have a datatable in memory that I've added a composite primary key to with
Code:
   myPeopleAssignmentsTable.PrimaryKey = New DataColumn() _
                {myPeopleAssignmentsTable.Columns("people_id"), _
                 myPeopleAssignmentsTable.Columns("assignment_id")}
as per an MS help file. Can't really find where the give an example of table.rows.find(compositekey) but I ran across this

Dim pKeys(2) as integer
pKeys(0) = 1
pKeys(1) = 2

table.rows.find(pKeys)

But that gives an error that says
Code:
Expecting 2 value(s) for the key being indexed, but received 1 value(s).
How do you define and provide a composite key to Find() with?
Reply With Quote
  #2  
Old 06-19-2014, 12:41 PM
PatM PatM is offline
Freshman
 
Join Date: Mar 2006
Posts: 28
Default

I think I found it. Instead of an integer array it should be an array of "Object" something like this

Dim keys(2) as object = new Object {1,2}

I dont remember exactly and I haven't tried it (at work). When I get home I'll see if it works.
Reply With Quote
  #3  
Old 07-02-2014, 07:03 AM
PatM PatM is offline
Freshman
 
Join Date: Mar 2006
Posts: 28
Default

I forgot to finish this one. Array of object does work but with VB2010 the array declaration seems whack.

When I use a relation table like this:
idFromTable1
idFromTable2
Primary key is both columns

then use this to find a row
Code:
Dim IDs(2) as Object
IDs(0) = 1
IDs(1) =4

myRow = MyTable.Rows.Find(IDs)
I get the error: Expecting 2 value(s) for the key being indexed, but received 3 value(s).

I have to dimension the object array as having one element

Dim IDs(1) as Object

Then it works properly.
I've always used a number saying the number of elements. This seems like its expecting the highest element number instead so specifying 1 means elements of 0 and 1 rather than 1 means there's only element 0.


Is it just me or is that a bug?
Reply With Quote
  #4  
Old 07-02-2014, 11:21 AM
PlausiblyDamp's Avatar
PlausiblyDamprows.find with composite key PlausiblyDamp is offline
Ultimate Contributor

Forum Leader
* Expert *
 
Join Date: Nov 2003
Location: Newport, Wales
Posts: 2,058
Default

Not a bug, that is how VB sizes an array - the number you specify is the index of the last element rather than the number of elements.
__________________
Intellectuals solve problems; geniuses prevent them.
-- Albert Einstein

Posting Guidelines Forum Rules Use the code tags
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
rows.find with composite key
rows.find with composite key
rows.find with composite key rows.find with composite key
rows.find with composite key
rows.find with composite key
rows.find with composite key rows.find with composite key rows.find with composite key rows.find with composite key rows.find with composite key rows.find with composite key rows.find with composite key
rows.find with composite key
rows.find with composite key
 
rows.find with composite key
rows.find with composite key
 
-->