Home All Groups Group Topic Archive Search About

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

Author
9 Nov 2005 5:59 PM
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

Author
10 Nov 2005 4:36 PM
mharness
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


Show quote
"mharness" <bo***@hotmail.com> wrote in message
news:8LCdnVatO4Yg2u_eRVn-hQ@comcast.com...
> 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
>

AddThis Social Bookmark Button