BindingSource.Find with multiple primary keys

F

Foef

I have a BindingSource with an underlying table with two primary keys.

To set the position with one primary key works fine as shown in the code
snippet below:
Dim index As Integer = myBindingSource.Find("ColumnName", myColumnName)
If (index <> -1) Then
myBindingSource.Position = index
End If

How should I set the BindingSource.Position with two or more primary keys?

Thanks
Foef
 
F

Foef

Found it at the German Newsgroup:

Dim par1 As Integer = 5
Dim par2 As Integer = 6
' Verweis auf Tabelle
Dim dt As DataTable = _
CType(bs1.DataSource, DataSet).Tables(bs1.DataMember)
' Filter aufbauen
Dim filter As String = _
String.Format("{0} = {1} AND {2} = {3}", _
dt.PrimaryKey(0).ColumnName, par1, _
dt.PrimaryKey(1).ColumnName, par2)
' DataRow heraussuchen
Dim rows() As DataRow = dt.Select(filter)
' auf Zeile positionieren
If rows.Length = 1 Then
Dim tempRows() As DataRow = dt.Select(bs1.Filter, bs1.Sort)
bs1.Position = Array.IndexOf(tempRows, rows(0))
Else
Trace.WriteLine("kein Satz gefunden")
End If
 

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