Identiy Columns

  • Thread starter Thread starter dhernando
  • Start date Start date
D

dhernando

Hi, I know how to get table columns with getoledbschematable and how to get the columns and type for a specific table but i need to know if a column have a identity type (incremental) please how can i get this information
 
Hi,

This is tricky, as it depends on provider:
for sqlserver it seems that column_flags = 16 and data_type=3 indicates
autonumbering
while for oledb/jet4 it seems that column_flags=90 and data_type=3 indicates
autonumbering

--
Miha Markic - RightHand .NET consulting & software development
miha at rthand com

dhernando said:
Hi, I know how to get table columns with getoledbschematable and how to
get the columns and type for a specific table but i need to know if a column
have a identity type (incremental) please how can i get this informationCommunity Website: http://www.dotnetjunkies.com/newsgroups/
 
There is another way but it is slower than what Miha has suggested.

DataAdatper has a method called FillSchema. Call this method and then
examine the DataColumn elements of the Table. DataColumn has Properties

1. AutoIncrement 2) AutoIncrementSeed 3) AutoIncrementStep
 
Thank you for help me, look i have this procedure, look in the last case "isautoincrement" looks ok but is not working everything else work fine please maybe you can see where is the error thanks a lot

cmd.CommandText = "SELECT * FROM " + tblName
cmd.Connection = cnn
myReader = cmd.ExecuteReader()
schemaTable = myReader.GetSchemaTable()
i=0
foreach (DataRow myField in schemaTable.Rows

foreach (DataColumn myProperty in schemaTable.Columns)

switch (myProperty.ColumnName.ToLower())

case "columnname"
listView1.Items.Add (myField[myProperty].ToString())
break
case "columnsize"
listView1.Items.SubItems.Add(myField[myProperty].ToString())
break
case "datatype"
listView1.Items.SubItems.Add(myField[myProperty].ToString())
break
case "isautoincrement"
listView1.Items.SubItems.Add(myField[myProperty].ToString())
break


i++
}
 
Back
Top