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

  • SEARCH
  • Home
  • 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 3443126
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:45:11+00:00 2026-05-18T08:45:11+00:00

I am working on a desktop application that returns list of tables that have

  • 0

I am working on a desktop application that returns list of tables that have foreign keys in a datagrid by this function.

       public void GetPrimaryKeyTable()

        {

        //An instance of the connection string is created to manage the contents of the connection string.
        var sqlConnection = new SqlConnectionStringBuilder();
        sqlConnection.DataSource = "192.168.10.3";
        sqlConnection.UserID = "gp";
        sqlConnection.Password = "gp";
        sqlConnection.InitialCatalog = Convert.ToString(cmbDatabases.SelectedValue);
        string connectionString = sqlConnection.ConnectionString;

        SqlConnection sConnection = new SqlConnection(connectionString);

        //To Open the connection.
        sConnection.Open();

        //Query to select the table_names that have PRIMARY_KEYS.
        string selectPrimaryKeys = @"SELECT 
                                           TABLE_NAME 
                                       FROM
                                           INFORMATION_SCHEMA.TABLE_CONSTRAINTS 
                                      WHERE 
                                           CONSTRAINT_TYPE = 'PRIMARY KEY'
                                        AND
                                           TABLE_NAME <> 'dtProperties'
                                   ORDER BY 
                                           TABLE_NAME";

        //Create the command object
        SqlCommand sCommand = new SqlCommand(selectPrimaryKeys, sConnection);

        try
            {
            //Create the dataset
            DataSet dsListOfPrimaryKeys = new DataSet("INFORMATION_SCHEMA.TABLE_CONSTRAINTS");

            //Create the dataadapter object
            SqlDataAdapter sDataAdapter = new SqlDataAdapter(selectPrimaryKeys, sConnection);

            //Provides the master mapping between the sourcr table and system.data.datatable
            sDataAdapter.TableMappings.Add("Table", "INFORMATION_SCHEMA.TABLE_CONSTRAINTS");

            //Fill the dataset
            sDataAdapter.Fill(dsListOfPrimaryKeys);

            //Bind the result combobox with primary key tables
            DataViewManager dvmListOfPrimaryKeys = dsListOfPrimaryKeys.DefaultViewManager;
            dgResultView.DataSource = dsListOfPrimaryKeys.Tables["INFORMATION_SCHEMA.TABLE_CONSTRAINTS"];
            }
        catch(Exception ex)
            {
            //All the exceptions are handled and written in the EventLog.
            EventLog log = new EventLog("Application");
            log.Source = "MFDBAnalyser";
            log.WriteEntry(ex.Message);
            }
        finally
            {
            //If connection is not closed then close the connection
            if(sConnection.State != ConnectionState.Closed)
                {
                sConnection.Dispose();
                }
            }
        }

Now I want to count the number of tables that fall in this category and display it in a lablel that this much of tables are under this category..

Can you guys please help me

  • 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-18T08:45:11+00:00Added an answer on May 18, 2026 at 8:45 am

    I believe you can just use the DataSet.Tables.Count method.
    http://msdn.microsoft.com/en-us/library/system.data.internaldatacollectionbase.count.aspx

    Or, DataSet.Tables[i].Rows.Count

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a desktop application that populate the list of all tables
I'm working on a desktop application that uses API keys for Twitter but AFAIK,
I'm working on a desktop application that will produce several in-memory datasets as an
I'm currently working on a project that is building a java-based desktop application to
I'm working with WPF and EF 4.2 to build a desktop application. I have
I've started working on a Java desktop application using netbeans. I have 7 different
I am currently working on a VB.NET desktop application that uses .mdb (Access) database
I am working on a desktop based application that is like drop box, I
I am currently working on a c# .NET desktop application that will be communicating
We have a Java desktop application that accesses a Derby database located on a

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.