Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6798331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T18:43:02+00:00 2026-05-26T18:43:02+00:00

I am using C# with MS Access 2010. I need to retrieve the table

  • 0

I am using C# with MS Access 2010. I need to retrieve the table relationships from the DB in order to determine the relationships between entities and use them in my C# code.
I need the same functionality for SQL Server database also.

Is there a way to do this using C# and .NET 3.0/ 3.5/ 4.0?

Appreciate your time.

Thanks,
Mahesh

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T18:43:02+00:00Added an answer on May 26, 2026 at 6:43 pm

    This is the code I used to retrieve the foreign key constraints (the relationships, if you prefer). TableSchema, ForeignKey and ForeignKeyColumn are my own classes, where I store the result. The point is to use the GetOleDbSchemaTable method of the OleDbConnection:

    private static void RetrieveForeignKeyInfo(OleDbConnection cnn, TableSchema tableSchema, Func<string, string> prepareColumnNameForMapping)
    {
        string[] fkRestrictions = new string[] { null, null, null, null, null, tableSchema.TableName };
        using (DataTable dtForeignKeys = cnn.GetOleDbSchemaTable(OleDbSchemaGuid.Foreign_Keys, fkRestrictions)) {
            ForeignKey foreignKey = null;
            string constraintName = "";
            foreach (DataRow row in dtForeignKeys.Rows) {
                string newConstraintName = (string)row["FK_NAME"];
                if (newConstraintName != constraintName) {
                    constraintName = newConstraintName;
                    foreignKey = new ForeignKey();
                    foreignKey.MasterTableName = (string)row["PK_TABLE_NAME"];
                    tableSchema.ForeignKeys.Add(foreignKey);
                }
                var foreignKeyColumn = new ForeignKeyColumn();
                foreignKeyColumn.DetailColumnName = (string)row["FK_COLUMN_NAME"];
                foreignKeyColumn.MasterColumnName = (string)row["PK_COLUMN_NAME"];
                foreignKeyColumn.DetailColumnNameForMapping = prepareColumnNameForMapping(foreignKeyColumn.DetailColumnName);
                foreignKeyColumn.MasterColumnNameForMapping = prepareColumnNameForMapping(foreignKeyColumn.MasterColumnName);
                foreignKey.Columns.Add(foreignKeyColumn);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Access 2003 I want to get a table value from the two databases
I am using the DoCmd.TransferText in MS-Access-2010 VBA to export a table to a
Using Access 2003 In my table column, some of the fields are null, some
Using Access Database Table ID Time 001 100000 001 100005 001 103000 001 102500
I have a Microsoft Access 2010 database(*). Now, using Visual Studio 2010, I want
I'm using VS 2010 with C# for a Windows Form application. I need to
I am trying to access the data from MS Access Database using C#. in
Dear all. I need to keep some temporary information in code. When i access
I have a problem with Access 2010. I'm using the included datepicker with the
I need to generate unique invoice numbers for my Access (2010) database. The numbers

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.