Advertisement

04.11.2008 at 12:36PM PDT, ID: 23316251
[x]
Attachment Details

The datatable.Rows.Contains() method does not find primary key

Asked by bd9000 in Microsoft Visual Basic.Net, .NET Framework 2.0

Tags: VB.NET ASP.NET 2

The datatable.Rows.Contains() method does not find the primary key value in the datatable and it definitely exists in the table.
I populated a datatable with a single column of values using a datareader, then set the PrimaryKey to column(0), the only column in the DataTable.   The values are there, for sure (64 rows X 1 column), in the datatable, but the statement

If dtProdImportFields.Rows.Contains("ProductName") Then
'do something
End If

does not work at all (the Contains function completely ignores the value passed to it Or I am not using it correctly).   The string "ProductName" is in the datatable and it is the PrimaryKey column and all values are unique, so I am stumped as to what may be going on.

Attached, is the code that generates the datatable (I think the problem may be that the PrimaryKey is somehow not being generated - though there are no errors)

Any ideas where I'm going wrong here?Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
Protected Sub GetProdImportFields(ByRef dtbl As DataTable)
        Dim sqlstring As String = "SELECT SSFieldName FROM ProdImportFields"
        Using connection As New SqlConnection(DBconnstr)
            connection.Open()
            Using command As New SqlCommand(sqlstring, connection)
                Using reader As SqlDataReader = command.ExecuteReader()
                    dtbl.Load(reader, LoadOption.OverwriteChanges)
                End Using
            End Using
        End Using
        dtbl.PrimaryKey = New DataColumn() {dtbl.Columns(0)} 'this appears correct
    End Sub
[+][-]04.11.2008 at 12:43PM PDT, ID: 21337522

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 12:45PM PDT, ID: 21337539

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 12:48PM PDT, ID: 21337559

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 12:50PM PDT, ID: 21337586

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 12:59PM PDT, ID: 21337677

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 01:00PM PDT, ID: 21337687

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 01:03PM PDT, ID: 21337721

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Microsoft Visual Basic.Net, .NET Framework 2.0
Tags: VB.NET ASP.NET 2
Sign Up Now!
Solution Provided By: VBRocks
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.11.2008 at 01:12PM PDT, ID: 21337805

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.11.2008 at 01:16PM PDT, ID: 21337832

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628