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 3422158
In Process

The Archive Base Latest Questions

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

I have a function to populate the list of all tables with primary keys

  • 0

I have a function to populate the list of all tables with primary keys in a selected db from a dropdown:

public void PrimaryKeyTable()
{

    //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();

    string selectPrimaryKeys = @"SELECT 
                                       TABLE_NAME 
                                   FROM
                                       INFORMATION_SCHEMA.TABLE_CONSTRAINTS 
                                  WHERE 
                                       CONSTRAINT_TYPE = 'PRIMARY KEY'
                               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;
        cmbResults.DataSource = dsListOfPrimaryKeys.Tables["INFORMATION_SCHEMA.TABLE_CONSTRAINTS"];
        cmbResults.DisplayMember = "TABLE_NAME";
        cmbResults.ValueMember = "TABLE_NAME";
        }
    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.Close();
            }
        }
}

Now I wish to call this function a button click like this:

private void btnStartAnalysis_Click(object sender, EventArgs e)
    {
        //This is the function call for the primary key checking in DB
        PrimaryKeyTable();
    }

Its working fine but when I want to call it on the button click when a particular text is selected from the dropdown like this:

private void btnStartAnalysis_Click(object sender, EventArgs e)
    {
        //This is the function call for the primary key checking in DB
        if(cmbOperations.SelectedText == "PrimaryKeyTables")
            {
            PrimaryKeyTable();
            } 
    }

Then it’s not giving any result…

Can anybody tell where I am going wrong?

  • 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-18T06:11:05+00:00Added an answer on May 18, 2026 at 6:11 am

    i think you should replace

    if(cmbOperations.SelectedText == "PrimaryKeyTables")
    

    with

    if((string)cmbOperations.SelectedValue == "PrimaryKeyTables")
    
    • 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 have a form that uses jQuery-UI's selectable plugin to populate a list from
I have code like function populate...() { var user = $.storage.get(particulars); if (user) {
Is it possible to populate a listview with a dataset? I have a function
I have a JTable inside a JScrollPane. After calling my function which should populate
I have a listbox with multiselect options. I populate it using the addItem function.
I have function LoadTempMovieList(), and need to load movies from sessionStorage. But it seems
i have function public Menu Details(int? id) { return _dataContext.Menu.Include(ChildMenu).FirstOrDefault(m => m.MenuId == id);
I have a dropdown list populated by mysql working perfectly, I also have it
I have a list of cities (simple cvs file) and I want to populate

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.