Finding A Record in a Dataset by index

D

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
 
C

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
 
J

james

DavidB said:
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
 
J

james

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top