I'm trying to query a datatable to establish the primary key [identity column], by querying each columns autoincrement property. However its always false (for the column which is the Idenity/PK).
Querying the tables primary key collection reveals that the datatable doesn't think it has a PK.;
Dim dc As DataColumn() = dt.PrimaryKey
Debug.WriteLine(dc.Count) 'Result is 0
The datatable is being populated.......
Using cn As SqlConnection = MyApp.GetConnection
Using cmd As New SqlCommand(strSQL, cn)
Using da As New SqlDataAdapter(cmd)
Dim ds As New DataSet
Try
da.Fill(ds)
Return ds
Catch ex As Exception
MyAppClass.LogWarning(ex, EventLogEntryType.Error)
Throw
End Try
End Using
End Using
End Using
The table in question's primary key is : ([myTableId] [int] IDENTITY(1,1) NOT NULL). and its the pk : CONSTRAINT [PK_myTablesPK] PRIMARY KEY CLUSTERED ( [myTableId] ASC )
Here's someone having the same problem (perhaps its clearer than what i've written) : http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataproviders/thread/c6abdeef-0cb0-42f5-a5f1-10dc4d81df4a/
I'm assuming its something simple i'm missing, does anyone care to enlighten me?