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.