Retrieving primary key info in ADO.NET

by lichen 7/17/2004 2:13:00 PM

By default, neither DataReader.GetSchema() nor DataTable.PrimaryKey contains the info of the Primary Key after executing a data select command.

To retrieve Primary Key using DataReader with data, use:

SqlSelectCommand1.ExecuteReader(CommandBehavior.KeyInfo)

To retrieve Primary Key using DataReader without data, use:

SqlSelectCommand1.ExecuteReader(CommandBehavior.KeyInfo Or CommandBehavior.SchemaOnly)

To retrieve Primary Key using DataReader with data, use:

SqlDataAdapter1.MissingSchemaAction = MissingSchemaAction.AddWithKey

SqlDataAdapter1.Fill(ds)

To retrieve Primary Key using DataReader with data, use:

SqlDataAdapter1.FillSchema(ds, SchemaType.Mapped)

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

.Net | SQL

Related posts

Comments

11/7/2004 9:26:00 PM

hnieef

hiw can i determine primary key using ADO in VB.

really need this..

thank you

hnieef us

Comments are closed

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

Name of author Author name
Something about me and what I do.

E-mail me Send mail

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

Pages

    Recent comments

    Authors

    Tags

      Disclaimer

      The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

      © Copyright 2010

      Sign in