By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,034 Members | 1,714 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,034 IT Pros & Developers. It's quick & easy.

PK auto increment on sgdb access

P: n/a
JO
hello,
how could i make to know if my column PK on access is auto increment.

with .net i use
Dim dtLstKP As DataTable =
MyConn.GetOleDbSchemaTable(OleDbSchemaGuid.Primary _Keys, New Object()
{Nothing, Nothing, strNomTable})

thx


bonjour
comment puis je savoir si la cle primaire primaire d'une table access
est auto incrementée ??

en .net j'utilise

Dim dtLstKP As DataTable =
MyConn.GetOleDbSchemaTable(OleDbSchemaGuid.Primary _Keys, New Object()
{Nothing, Nothing, strNomTable})
merci
Mar 12 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
JO wrote:
how could i make to know if my column PK on access is auto increment.

with .net i use
Dim dtLstKP As DataTable =
MyConn.GetOleDbSchemaTable(OleDbSchemaGuid.Primary _Keys, New Object()
{Nothing, Nothing, strNomTable})
<snip>

I don't think you'll manage to do it using the Access schemata...

You could use ADODB, I guess.

<aircode>
Dim R As New ADODB.Recordset
R.Open( _
String.Format( _
"select {1} from {0} where 1=0", TableName, IDField), _
ConnectionString, _
ADODB.CursorTypeEnum.adOpenStatic, _
ADODB.LockTypeEnum.adLockReadOnly)

Dim IsAutoIncrement As Boolean = _
CType(R(IDField).Properties("IsAutoIncrement").Val ue, Boolean)

R.Close()
System.Runtime.InteropServices.Marshal.ReleaseComO bject(R)
</aircode>

HTH.

Regards,

Branco.

PS: "aircode" above means that you can't simply copy paste the code;
you'll need to refactor it somehow to suit your needs. It also means
that the code *may* have been typed directly in this response, so
typing errors may happen. It *doesn't* mean that I didn't test the
concept that the code relies on (which I did).

Mar 12 '07 #2

P: n/a
Here's one way to get the attributes of the columns in a table. I've done
this with SQLServer. My theory is if you change SqlConnection to
OLEDBConnection and SQLCommand to OLEDBCommand and SqlDataReader to
OLEDBDataReader, this will work against Access. But I haven't tried it.

Dim cn As New SqlConnection(My.Settings.DBConnString)
'put the table name in brackets in case it has spaces in it
Dim SQLString As String = "SELECT * FROM [" & tableName & "]"
Try
cn.Open()
Dim cmd As New SqlCommand(SQLString, cn)
Dim rdr As SqlDataReader = _
cmd.ExecuteReader(CommandBehavior.KeyInfo)
Dim tbl As DataTable = rdr.GetSchemaTable
'Uncomment this to see all of the info
' you can access about each column.
'For Each col As DataColumn In tbl.Columns
' Debug.Print("col name = " & col.ColumnName & _
' ", type = " & col.DataType.ToString)
'Next
For Each row As DataRow In tbl.Rows
Debug.Print("{0}, IsKey = {1}, IsIdentity = {2} ", _
row("ColumnName"), row("IsKey"), row("IsIdentity"))
Next
rdr.Close()
Catch
MessageBox.Show("Error opening the connection to the database.")
Finally
cn.Close()
End Try

I think the IsIdentity value is what you are looking for.

Robin S.
-------------------------
"JO" <no****@nospam.frwrote in message
news:mn***********************@nospam.fr...
hello,
how could i make to know if my column PK on access is auto increment.

with .net i use
Dim dtLstKP As DataTable =
MyConn.GetOleDbSchemaTable(OleDbSchemaGuid.Primary _Keys, New Object()
{Nothing, Nothing, strNomTable})

thx


bonjour
comment puis je savoir si la cle primaire primaire d'une table access est
auto incrementée ??

en .net j'utilise

Dim dtLstKP As DataTable =
MyConn.GetOleDbSchemaTable(OleDbSchemaGuid.Primary _Keys, New Object()
{Nothing, Nothing, strNomTable})
merci


Mar 13 '07 #3

P: n/a
JO
Dans son message précédent, RobinS a écrit :
Here's one way to get the attributes of the columns in a table. I've done
this with SQLServer. My theory is if you change SqlConnection to
OLEDBConnection and SQLCommand to OLEDBCommand and SqlDataReader to
OLEDBDataReader, this will work against Access. But I haven't tried it.

Dim cn As New SqlConnection(My.Settings.DBConnString)
'put the table name in brackets in case it has spaces in it
Dim SQLString As String = "SELECT * FROM [" & tableName & "]"
Try
cn.Open()
Dim cmd As New SqlCommand(SQLString, cn)
Dim rdr As SqlDataReader = _
cmd.ExecuteReader(CommandBehavior.KeyInfo)
Dim tbl As DataTable = rdr.GetSchemaTable
'Uncomment this to see all of the info
' you can access about each column.
'For Each col As DataColumn In tbl.Columns
' Debug.Print("col name = " & col.ColumnName & _
' ", type = " & col.DataType.ToString)
'Next
For Each row As DataRow In tbl.Rows
Debug.Print("{0}, IsKey = {1}, IsIdentity = {2} ", _
row("ColumnName"), row("IsKey"), row("IsIdentity"))
Next
rdr.Close()
Catch
MessageBox.Show("Error opening the connection to the database.")
Finally
cn.Close()
End Try

I think the IsIdentity value is what you are looking for.

Robin S.
-------------------------
"JO" <no****@nospam.frwrote in message
news:mn***********************@nospam.fr...
>hello,
how could i make to know if my column PK on access is auto increment.

with .net i use
Dim dtLstKP As DataTable =
MyConn.GetOleDbSchemaTable(OleDbSchemaGuid.Primar y_Keys, New Object()
{Nothing, Nothing, strNomTable})

thx


bonjour
comment puis je savoir si la cle primaire primaire d'une table access est
auto incrementée ??

en .net j'utilise

Dim dtLstKP As DataTable =
MyConn.GetOleDbSchemaTable(OleDbSchemaGuid.Primar y_Keys, New Object()
{Nothing, Nothing, strNomTable})
merci

thx you this is the good solve +a
Mar 13 '07 #4

P: n/a

"JO" <no****@nospam.frwrote in message
news:mn***********************@nospam.fr...
Dans son message précédent, RobinS a écrit :
>Here's one way to get the attributes of the columns in a table. I've
done this with SQLServer. My theory is if you change SqlConnection to
OLEDBConnection and SQLCommand to OLEDBCommand and SqlDataReader to
OLEDBDataReader, this will work against Access. But I haven't tried it.

Dim cn As New SqlConnection(My.Settings.DBConnString)
'put the table name in brackets in case it has spaces in it
Dim SQLString As String = "SELECT * FROM [" & tableName & "]"
Try
cn.Open()
Dim cmd As New SqlCommand(SQLString, cn)
Dim rdr As SqlDataReader = _
cmd.ExecuteReader(CommandBehavior.KeyInfo)
Dim tbl As DataTable = rdr.GetSchemaTable
'Uncomment this to see all of the info
' you can access about each column.
'For Each col As DataColumn In tbl.Columns
' Debug.Print("col name = " & col.ColumnName & _
' ", type = " & col.DataType.ToString)
'Next
For Each row As DataRow In tbl.Rows
Debug.Print("{0}, IsKey = {1}, IsIdentity = {2} ", _
row("ColumnName"), row("IsKey"), row("IsIdentity"))
Next
rdr.Close()
Catch
MessageBox.Show("Error opening the connection to the database.")
Finally
cn.Close()
End Try

I think the IsIdentity value is what you are looking for.

Robin S.
-------------------------
"JO" <no****@nospam.frwrote in message
news:mn***********************@nospam.fr...
>>hello,
how could i make to know if my column PK on access is auto increment.

with .net i use
Dim dtLstKP As DataTable =
MyConn.GetOleDbSchemaTable(OleDbSchemaGuid.Prima ry_Keys, New Object()
{Nothing, Nothing, strNomTable})

thx


bonjour
comment puis je savoir si la cle primaire primaire d'une table access
est auto incrementée ??

en .net j'utilise

Dim dtLstKP As DataTable =
MyConn.GetOleDbSchemaTable(OleDbSchemaGuid.Prima ry_Keys, New Object()
{Nothing, Nothing, strNomTable})
merci


thx you this is the good solve +a

Good, I'm glad it worked.

Robin S.
Mar 13 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.