Table doesn't have a primary key--actually has two

  • Thread starter Thread starter mharness
  • Start date Start date
M

mharness

Hello,

I'm trying to determine if a keyfield exists in a datagrid so that I can add
it to the datagrid if it's not there or remove it if it is.

When I try to use "contains" I get the error but it's not because there is
NO primary key it's because I have TWO primary keys. The dataset datasource
for my datagrid is the result of a query on two joined tables, each of which
have key fields.

I've tried returning only one of the keys in the resulting dataset but I
still get the error. I've also tried removing the key on one of the tables
and although that takes care of this problem it has and will obviously
create others problems.

So, what method do I use to find a key field or any other field for that
matter in a datagrid with two key fields?

Many thanks,

Mike
 
Turns out it was easier to ignore the keys and just...

Public Shared Function ValueInDatagrid(ByVal str As String, ByVal dg As
DataGrid, ByVal col As Integer) As Boolean
'searches a datagrid column for a value
Dim Item As DataGridItem
For Each Item In dg.Items
If str = Item.Cells(col).Text Then
Return True
End If
Next Item
Return False
End Function
 
Back
Top