Home All Groups Group Topic Archive Search About

Finding A Record in a Dataset by index

Author
20 Apr 2006 4:36 AM
DavidB
New to .net....sorry if this seems repetitive

I have a dataset ordered by date (SQLDataAdapter SelectCommand uses
Order By) and want to find a record by a UniqueID(Identity Column).
Then I want to change the position (BindingContext) in the dataset to
have all my bound controls reflect the data in the found record - and
the related records/tables.
Problem is, it appears it can't be done....
The Dataset has to be ordered by the date column, and the UniqeID (int)
is the primary key.

The solution of creating a Dataview and finding the record is not a
real-world solution as it requires the sort order to be changed (from
date to identity column). Hence the index of the found item is unlikely
to be correct.

I think many people have travelled this path before but I can't find
any useful info relating to this exact issue

If you can help, please do..
DB

Author
20 Apr 2006 8:21 AM
Cor Ligthert [MVP]
David,

Reading your message I got the idea that you to solve our problem first have
to understand what the Dataset is.

A short try in advance.

A dataset is a kind of wrapper around datatables and datarelation.
A datatable holds datarows, datacolumns and a defaultview
A datarelation holds a relation to datarows in datatables
A defaultview holds sort, selections for rows you can use more and than the
name becomes DataView.
A datarow holds items which have a description in the datacolumns.
The last is the reason that a datarow can never belong to another table. It
has the reference to the table and its columns in it.

There are a lot of find methods.
DataView.Find
DataTable.Select
DataView.Rowfilter
DataTable.Collection.Find

If you study this a little bit by instance on MSDN, than your problem will
be in my idea be solvable.

I hope this helps,

Cor
Author
20 Apr 2006 3:51 PM
james
Show quote Hide quote
"DavidB" <d9.buc***@cairns.qld.gov.au> wrote in message
news:1145507797.941238.246070@g10g2000cwb.googlegroups.com...
> New to .net....sorry if this seems repetitive
>
> I have a dataset ordered by date (SQLDataAdapter SelectCommand uses
> Order By) and want to find a record by a UniqueID(Identity Column).
> Then I want to change the position (BindingContext) in the dataset to
> have all my bound controls reflect the data in the found record - and
> the related records/tables.
> Problem is, it appears it can't be done....
> The Dataset has to be ordered by the date column, and the UniqeID (int)
> is the primary key.
>
> The solution of creating a Dataview and finding the record is not a
> real-world solution as it requires the sort order to be changed (from
> date to identity column). Hence the index of the found item is unlikely
> to be correct.
>
> I think many people have travelled this path before but I can't find
> any useful info relating to this exact issue
>
> If you can help, please do..
> DB


In your SQL statement, you can select only the row(s) that have the UniqueID
you are looking for pretty easy.
Something similar to this:

" Select * From <tablename goes here> Where [ColumnName goes here] = " &
UniqueIDvalue & " Order By [Date]"

<tablename goes here> is the name of the table you are searching in ( just
put the table name not the < >.
ColumnName goes here is the name of the Column that contains the
UniqueIDvale that you are looking for.( keep the brackets)
UniqueIDvalue can be a string that contains the value you are searching for.

I think you get the idea here. You select all of the table's columns and
search for only the row(s) that have the value you are looking for in a
particular column.  Or if you only need a few of the table's columns, you
can modify the Select portion of the statement similar to :
"Select [column1], [column2], [column3], [column4] Where [Column3] =" &
UnidueIDvalue & " Order By [column1]"

Hope this is what you are looking for.
james
Author
20 Apr 2006 4:18 PM
james
Show quote Hide quote
"james" <jjames700REMOV***@earthlink.net> wrote in message
news:uYg5SJJZGHA.1200@TK2MSFTNGP03.phx.gbl...
>
> "DavidB" <d9.buc***@cairns.qld.gov.au> wrote in message
> news:1145507797.941238.246070@g10g2000cwb.googlegroups.com...
>> New to .net....sorry if this seems repetitive
>>
>> I have a dataset ordered by date (SQLDataAdapter SelectCommand uses
>> Order By) and want to find a record by a UniqueID(Identity Column).
>> Then I want to change the position (BindingContext) in the dataset to
>> have all my bound controls reflect the data in the found record - and
>> the related records/tables.
>> Problem is, it appears it can't be done....
>> The Dataset has to be ordered by the date column, and the UniqeID (int)
>> is the primary key.
>>
>> The solution of creating a Dataview and finding the record is not a
>> real-world solution as it requires the sort order to be changed (from
>> date to identity column). Hence the index of the found item is unlikely
>> to be correct.
>>
>> I think many people have travelled this path before but I can't find
>> any useful info relating to this exact issue
>>
>> If you can help, please do..
>> DB
>
I need my 4th cup of coffee again!! You are wanting to do this from a
Dataset and not from a SQL Query Statement.
Sorry about that.
james