 |
| 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
|
|
|
|

April 28th, 2004, 06:03 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
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.
|
|

April 28th, 2004, 07:40 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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'"
|
|

April 28th, 2004, 08:02 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
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.
|
|

April 28th, 2004, 10:39 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

April 29th, 2004, 12:44 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
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.
|
|

May 1st, 2004, 12:00 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
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.
|
|

May 3rd, 2004, 06:51 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

May 3rd, 2004, 08:59 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
|
|
Yes I got it Brian. Anyway I solved my problem & tnx for responce.
Always:),
Hovik Melkomian.
|
|
 |