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

Re: need to know the primary key of a table by Sahil

Sahil
Wed Jan 26 13:14:52 CST 2005

Try FillSchema instead of Fill.

Alternatively, use a Command.ExecuteReader with CommandBehavior.Schema
(don't remember exactly which one, but it's there).

- Sahil Malik
http://dotnetjunkies.com/weblog/sahilmalik



"toufik" <touiss@hotmail.com> wrote in message
news:uoFn5n9AFHA.3504@TK2MSFTNGP12.phx.gbl...
> 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
>
>



RE: need to know the primary key of a table by AshishKelo

AshishKelo
Thu Jan 27 14:03:03 CST 2005

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

"toufik" wrote:

> 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
>
>
>