need to know the primary key of a table

T

toufik

Hi,

in order to know the primary key of a table in my dataset, i've the folowing
code

sql "select * from table1"
create a dataadapter with this sql DA
fill the dataadapter in a dataset DS
DS.Tables(0).PrimaryKey

but the expression returns me an empty array, is there any problem? is there
another way to get the primary key of a table.

I use vb.net and an MSACCESS2000 database.
Thanks
 
G

Guest

Toufik,

Identification of a Primary key in a Dataset can be only done when using a
connected Dataset, else you need to define the Key and Relationship of the
records.
Primary Key of a DataTable is a get set property. This will help your for sure

Dim Arr() As DataColumn
Arr = myTable.PrimaryKey
Dim i As Integer
For i = 0 To Arr.GetUpperBound(0)
Console.WriteLine(Arr(i).ColumnName & Arr(i).DataType.ToString())
Next i

Let me know this should work in identification of Primary Key.

Thanks,
Ashish Kelo
 

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