简体   繁体   中英

Query to get primary key of table in access database

What query we need to write for access database to get primary key column name of a particular table.

I ma using c# and access database whose file format is .mdb. I am using OleDbConnection class.

I want to get primary key column name in access database using query which is something like select columnName from sys.information_schema. This query work with sql server. I want query something like this which work with ms access.

Thanks.

this could be of help: http://gsraj.tripod.com/dotnet/ado_net/ado.net_retrieving_database_metadata.html

together with this: http://msdn.microsoft.com/en-us/library/system.data.datatable.primarykey.aspx

edit after comments: i was wrong:

SELECT MSysObjects.* FROM MSysObjects

you'll have to google the details tho, gotta go...

I actually figured it out. Just like what Awadhendra said i have to make an primary column that is hidden which is what i did.

this is the code that got the first column which is hidden.

String SelectedID = dgvInventory.Rows[dgvInventory.CurrentRow.Index].Cells[0].Value.ToString();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM