newbie: forms databinding question

  • Thread starter Thread starter Dan
  • Start date Start date
D

Dan

I have a c# windows application binding some controls to a source table: I
can browse the table records by retrieving the CurrencyManager from the
form's BindingContext for my dataset and table and using the Position
property; but I'd like the form to show on demand A SPECIFIC RECORD (if
existing): i.e. I'd like to find a specific record as with the
DataTable.Select method, and set it as the CURRENT record for my form if
found. How can I do this? I don't think I can use Select as it rets a set of
rows but not their index in the table... and I'd need an index to set
CurrencyManager Position.

Thx to all guys!
 
Hi Dan
You can put a check Condition like if userenteredValue < TableRowsCount
then GO ahead and Show that row by setting the Position .
Code may look like this (Products is a Table)
Me.BindingContext(Dataset11, "Products").Position = UserEnteredValue

Alternatively you can get the Row from the Dataset
Like this for a Typed Dataset where Categories is a Table
Dataset11.Categories(UserEnteredValue ).CategoryName


Thanks
Sunder
VB.net
 
Thanks, anyway if I understand well these are ways of setting the position
to a specified index; my question was, how can I retrieve that index when
I'm searching for a specified value in a set of rows? E.g. let's say I have
a dataset with a table with some contacts, I want to find the index for the
contact named "Donald Duck" and then set this record (if found) as the
current row for my bound controls...
 
Hi Dan
Unfortunately there is no Direct Support to Get the Row Index of a Row as
DatarowCollection doesnt implement IList. To get the Row Index
you should Iterate thru all Records of a Dataset to get the Row Index
Sample Code may Look Like this

Dim index As Integer
For index = 0 To DataSet11.Categories.Rows.Count - 1
If DataSet11.Categories(index).CategoryID = "Your Value" Then
Return index
End If
Next

This will Defintely Hit Performance .

Alternative you can have a Parameterized Query Which will Take ContactName
and Fill the Dataset
.So your dataadapter Query may look like
Select * from Names where ContactName = @ContactName

You can Pass in the Contact Name at run time and Fill the Dataset . This
will be Fast and Efficient

There are some Examples on MSDN to Use Parameterized Query
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
ml/databindingadonet.asp

Thanks
Sunder
Vb.Net
--------------------
 
What about GetOrdinal?

Sunder Thondamuthur said:
Hi Dan
Unfortunately there is no Direct Support to Get the Row Index of a Row as
DatarowCollection doesnt implement IList. To get the Row Index
you should Iterate thru all Records of a Dataset to get the Row Index
Sample Code may Look Like this

Dim index As Integer
For index = 0 To DataSet11.Categories.Rows.Count - 1
If DataSet11.Categories(index).CategoryID = "Your Value" Then
Return index
End If
Next

This will Defintely Hit Performance .

Alternative you can have a Parameterized Query Which will Take ContactName
and Fill the Dataset
So your dataadapter Query may look like
Select * from Names where ContactName = @ContactName

You can Pass in the Contact Name at run time and Fill the Dataset . This
will be Fast and Efficient

There are some Examples on MSDN to Use Parameterized Query
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dndotnet/ht
 
Back
Top