PC Review


Reply
Thread Tools Rate Thread

Determing which column is identity column

 
 
Doug
Guest
Posts: n/a
 
      15th Dec 2005
Hi,
I am querying the database and sticking the results into a datatable.
It would be helpful though if I could determine programmatically which
column in that datatable is the identity column (if there is one). Is
there a way to do this?

 
Reply With Quote
 
 
 
 
Miha Markic [MVP C#]
Guest
Posts: n/a
 
      15th Dec 2005
Hi Doug,

I guess you are using .net 1.x.
One of the options is to use OleDbConnection.GetOleDbSchemaTable. The other
option would be to use database specific ddl queries.

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

"Doug" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I am querying the database and sticking the results into a datatable.
> It would be helpful though if I could determine programmatically which
> column in that datatable is the identity column (if there is one). Is
> there a way to do this?
>



 
Reply With Quote
 
W.G. Ryan - MVP
Guest
Posts: n/a
 
      15th Dec 2005
In addition to Miha's comments, once the datatable is filled I think y ou
can loop through the datacolumns and check the Autoincrement property - if
it's true, that's it.
"Doug" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I am querying the database and sticking the results into a datatable.
> It would be helpful though if I could determine programmatically which
> column in that datatable is the identity column (if there is one). Is
> there a way to do this?
>



 
Reply With Quote
 
Doug
Guest
Posts: n/a
 
      15th Dec 2005
AutoIncrement doesn't work because it's a property of the dataset
itself and not the data from the database that is in the dataset.

I am using version 1.1.

I am trying to use the Data Access Block that Microsoft provides and so
in my actual app, I don't have access to the connection object (it's
open source code so I could go into it and manipulate it, but that's a
last step for me). I was just wondering if some property of the
DataSet would properly reflect that a column is a identity column.

 
Reply With Quote
 
W.G. Ryan - MVP
Guest
Posts: n/a
 
      16th Dec 2005
Doug - the adapter builds the schema for the datatable based on the db if
you don't specify it. I thought Autoincrement came back - lemme double check
it.

I'm afraid you're going to have to modify the code though if you want to
use the GetSchemaTable or similar approach
"Doug" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> AutoIncrement doesn't work because it's a property of the dataset
> itself and not the data from the database that is in the dataset.
>
> I am using version 1.1.
>
> I am trying to use the Data Access Block that Microsoft provides and so
> in my actual app, I don't have access to the connection object (it's
> open source code so I could go into it and manipulate it, but that's a
> last step for me). I was just wondering if some property of the
> DataSet would properly reflect that a column is a identity column.
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Primary Key, Identity Column - Problem adding row to strongly typed data table - "Column 'ShipmentID' does not allow nulls." stephanieschipper@yahoo.com Microsoft ADO .NET 0 12th Dec 2006 02:14 AM
identity column Felix González Microsoft Dot NET Compact Framework 1 12th Apr 2005 06:51 PM
Q: Determing in a column in a datagrid Geoff Jones Microsoft VB .NET 3 20th Nov 2004 03:31 PM
Determing DataType for a returned DataSet Column =?Utf-8?B?QW1lbGlh?= Microsoft ADO .NET 3 25th Sep 2004 03:15 AM
Determing MaxLength of SQLCE DB Column Joe Keller Microsoft Dot NET Compact Framework 0 4th Feb 2004 03:34 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:50 AM.