PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Help. Determine PrimaryKey Column from sqlDataReader
Forums
Newsgroups
Microsoft DotNet
Microsoft ADO .NET
Help. Determine PrimaryKey Column from sqlDataReader
![]() |
Help. Determine PrimaryKey Column from sqlDataReader |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hi,
I have an open and active sqlDataReader object and would like to determine which of the fields is the PrimaryKey (if present). I intend to use this to create generic DataTable objects in a library by passing in a sqlDataReader object, and the library returns a DataTable object from the reader. This all works fine so far, but I cannot find a way to determine which field in the sqlDataReader is the PrimaryKey so as to set the corresponding Column in the DataTable as the PrimaryKey. Any help appreciated. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
use the dataaapter instead of the reader. Readers are "forward only
cursors" so to speak and used to quickly read data. The DataAdapter will FILL your data set and your column will already be there! snipet System.Data.SqlClient.SqlConnection con; System.Data.DataSet ds=null; System.Data.SqlClient.SqlDataAdapter adap=new System.Data.SqlClient.SqlDataAdapter("select * from table",con); ds=new DataSet(); adap.Fill(ds); ds.Tables[0].PrimaryKey[0]; the PrimaryKey is an array of dataColumns! to cut down on size, use TOP or select less columns in the query or check the FILL method to limit the records collected. "SMS_Dev_Dept" <SMSDevDept@discussions.microsoft.com> wrote in message news:AB2316EE-8524-4DAA-B996-6AEF488C5C5E@microsoft.com... > Hi, > I have an open and active sqlDataReader object and would like to determine > which of the fields is the PrimaryKey (if present). > I intend to use this to create generic DataTable objects in a library by > passing in a sqlDataReader object, and the library returns a DataTable object > from the reader. This all works fine so far, but I cannot find a way to > determine which field in the sqlDataReader is the PrimaryKey so as to set the > corresponding Column in the DataTable as the PrimaryKey. > Any help appreciated. |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

