How to detect identity (oleDb)

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
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
 
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!

Piyush Thakuria said:
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

net_learner_sp said:
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.
 
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
 
Great, it worked!!

It's exactly what i was looking for.

THANK YOU!!

==============================
 
Back
Top