Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET Database and Reporting > Using Datatable Compound Key


Reply
 
Thread Tools Display Modes
  #1  
Old 05-08-2008, 02:01 PM
Gwattz Gwattz is offline
Newcomer
 
Join Date: Jan 2006
Posts: 5
Default Using Datatable Compound Key


I am trying to search a datatable using a compound key. I can create the compound key just fine, but when I go to create an object to pass to the find it give me an error. Below is a sample of my code. Any suggestions?

dim lblDT...etc...

Here is where I create the compound key, and it seems fine.

lblDT.PrimaryKey = New DataColumn() {lblDT.Columns("serialno"), _
lblDT.Columns("type")}


This is where I am trying to create an object to pass to the .find

dim objSearch As New Object() {10643, 28}

it if would work this is how the find would be.

Dim row As DataRow = lblDT.Rows.Find(objSearch)
Reply With Quote
  #2  
Old 05-08-2008, 05:18 PM
MKoslof's Avatar
MKoslof MKoslof is offline
Cum Grano Salis

Retired Moderator
* Guru *
 
Join Date: Jul 2002
Location: Baltimore, Maryland
Posts: 14,636
Default

What is the error you are receiving? When you say compound key is this only in memory or the .Net level? Are your actual tables (the database if being used) using a composite primary key? If this is a simple data structure being built in memory where do you populate the table, what type of data is this?
__________________
"Artificial Intelligence is no match for natural stupidity." ~unknown
Reply With Quote
  #3  
Old 05-12-2008, 09:10 AM
Gwattz Gwattz is offline
Newcomer
 
Join Date: Jan 2006
Posts: 5
Default

I was getting an invalid type, but I did figure out what I was doing wrong. The object DIM needs to be as follows:

Dim objFilter() As Object = {table1, table2}

Using this with the filter option seems to work out well, I know their are other ways (dataview etc..), I was just being a stubborn JA and wanted to get it done with Datatabel.

Thanks everyone for tying :-)
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
 
 
-->