Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 28th, 2004, 06:03 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default find not primary field in DataSet

Dear all:
Suppose I have following table in my DataSet.
Code:
F1 int [u]primary</u>
F2 int
F3 string
F1 is primary but I wanna search records by using F3 field.
I use dataSet.table.Rows.Find( "some-text" ); but since its not primaryKey It gives error

Can any1 help me?!

Always:),
Hovik Melkomian.
__________________
Always,
Hovik Melkomian.
 
Old April 28th, 2004, 07:40 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

You could either temporarily change the F3 field to the primary key, or use a DataView as such:

objView = dataset.table(0).DefaultView
objView.RowFilter = "F3 = 'some text'"
 
Old April 28th, 2004, 08:02 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

I know ur second way
Code:
objView.RowFilter = "F3 = 'some text'"
But filter is void method & does not return a DataRow witch I need.
& about ur first solution, Do u mean to change PrimaryKey temporarily?! What about when it has a relation with a table, I cant change Key?! Can u tell me more about it?

Tnx in Advance.

Always:),
Hovik Melkomian.
 
Old April 28th, 2004, 10:39 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

You're right. I didn't know if you had a DataRelation set up or not. With the data view, you can get a DataRow object. After you set up the row filter, you can do:

objView.Item(0).Row

Which will return a DataRow reference.

Other than this, the only other way I know how is to iterate row-by-row unfortunately.

Hope this helps,

Brian Mains
 
Old April 29th, 2004, 12:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Dear Brian:
Tnx for ur responce but can I ask u where did u find Item property for DataView Obj.?!? I cant see anything like that in my VS.net!
What version u r using?!
Code:
objView.Item(0).Row
Always:),
Hovik Melkomian.
 
Old April 29th, 2004, 07:20 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I'm using VS.NET 2003. Here's the link off of the MSDN site for this property.

http://msdn.microsoft.com/library/de...sitemtopic.asp

Brian
 
Old May 1st, 2004, 12:00 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Ok I use VS.new 2003 but I guess its jor JScript & VB not for me who is using C#! Anyway if u meant that
Code:
in C# >> objView.Table.Row[Index]
it wont be my answer since when I filter Dataview, It doesnt remove the rows that r not maching filter!
It just show the filtered rows but original rows r still in their position.
Bye the way, I solve my problem, & tnx for ur responce.

Always:),
Hovik Melkomian.
 
Old May 3rd, 2004, 06:51 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Sorry, I didn't realize there was no C# example. For C#, try this instead:

objView[index of row].Row

Was this your solution?

Brian
 
Old May 3rd, 2004, 08:59 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

Yes I got it Brian. Anyway I solved my problem & tnx for responce.

Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
dataset and autoincrement primary key be03024 ADO.NET 8 July 19th, 2009 12:09 PM
Update Table with dataset without primary key ranakdinesh ASP.NET 2.0 Professional 1 September 28th, 2006 05:30 PM
How to drop a field with primary key jeffcflam Pro VB Databases 1 May 4th, 2006 01:51 PM
Find() With multiple primary keys busher ASP.NET 1.0 and 1.1 Professional 0 June 2nd, 2005 03:00 PM
find by primary key mamidi Java Databases 0 December 17th, 2004 10:55 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.