Re: Determine PrimaryKey Column from sqlDataReader (ADO.NET)
- From: "John Kortis" <jkortis@xxxxxxxxxxxxxxx>
- Date: Tue, 7 Feb 2006 10:00:45 -0500
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" <SMS_Dev_Dept@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:9494F949-6251-42D1-8437-1F26D9ED6CD2@xxxxxxxxxxxxxxxx
Hi,The
I have an open sqlDataReader object. I would like to create a DataTable
object from this reader that contains the PrimaryKey column as well. The
sqlDataReader was opened using a SQL query like 'SELECT * FROM tblData'.
underlying table has 3 columns, of which the first is the Primary key.
.