Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / May 2005

Tip: Looking for answers? Try searching our database.

How to detect identity (oleDb)

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
net_learner_sp - 17 May 2005 09:16 GMT
Hello (sorry for my english),

i'm trying to detect whether a column in a table of a database (sql server,
access, mysql, ...) is identity and i'm not able to get it.

I first used GetOleDbSchemaTable and it didn't work.. then i tried a simple
'select top 1* from table' and got the value of 'AutoIncrement' for the
obtained columns.. it neither worked..

Can anyone give me an "adonet ole-db" compatible solution? I have searched
for so long and i don't know what else to do.

Thank you.
Piyush Thakuria - 17 May 2005 10:51 GMT
Hi,

You can take the table in the dataset and can use the following C# code to
determine the Autoincrement value

dtEmployee.Tables[0].Columns[0].AutoIncrement  

In the above case the first table in the dataset has the first column name
as identity.

The above statement would return you true or false.

Thanks and Regards,

Piyush Thakuria

> Hello (sorry for my english),
>
[quoted text clipped - 9 lines]
>
> Thank you.
net_learner_sp - 17 May 2005 12:17 GMT
Thanks for being so fast!!

As i said before, i have already tried that solution with an Access database
and it has not worked. Can it be some type of bug related only to Access?

(it's giving me 'false' for all the columns and one of them is autonumeric
[Identity] )

Thank you again!

> Hi,
>
[quoted text clipped - 25 lines]
> >
> > Thank you.
Kerry Moorman - 17 May 2005 13:11 GMT
net_learner_sp,

Here is an example:

       Dim connectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=CourseInfo.mdb;"
       Dim cn As New OleDb.OleDbConnection(connectionString)
       Dim cmd As New OleDb.OleDbCommand
       Dim rdr As OleDb.OleDbDataReader
       Dim tbl As DataTable

       cmd.CommandText = "Select * From Students"
       cn.Open()
       cmd.Connection = cn
       rdr = cmd.ExecuteReader(CommandBehavior.SchemaOnly Or
CommandBehavior.KeyInfo)
       tbl = rdr.GetSchemaTable
       rdr.Close()

       Dim row As DataRow
       For Each row In tbl.Rows
           If row("IsAutoIncrement") Then
               MsgBox(row("ColumnName") & " is autoincrement")
           End If
       Next

Kerry Moorman

> Hello (sorry for my english),
>
[quoted text clipped - 9 lines]
>
> Thank you.
net_learner_sp - 17 May 2005 13:53 GMT
Great, it worked!!

It's exactly what i was looking for.

THANK YOU!!

==============================

> net_learner_sp,
>
[quoted text clipped - 37 lines]
> >
> > Thank you.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.