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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:25:19+00:00 2026-05-18T10:25:19+00:00

I have a function like this for binding the primary key from the selected

  • 0

I have a function like this for binding the primary key from the selected database in a ComboBox:

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

But it is giving an unwanted result like dtproperties.Is anything wrong with the query.

  • 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-18T10:25:19+00:00Added an answer on May 18, 2026 at 10:25 am

    dtproperties is a table used by SQL Server to store diagram information. In some versions of SQL Server it is marked as a user table (rather than a system table) and so will get returned by queries that look for user table.

    Maybe just filter it out with something like this:

    string selectPrimaryKeys = @"SELECT 
                                           TABLE_NAME 
                                       FROM
                                           INFORMATION_SCHEMA.TABLE_CONSTRAINTS 
                                      WHERE 
                                           CONSTRAINT_TYPE = 'PRIMARY KEY'
                                           AND TABLE_NAME <> 'dtproperties'
                                   ORDER BY 
                                           TABLE_NAME";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm relatively new to DLL importing and function binding. Let's say I have a
Is there a way to have mutable function arguments in F#, that would allow
First of all i have to do this without IB and without advanced Objective-C
I have a ComboBox (Windows Forms) that is bound to a List. It is
I have a DataGrid with a NumericStepper as the item editor for one of
Usually when I subscribe to an event, I use the Visual Studio builtin function
I am having a lot of trouble binding my Json data to a JqGrid.
I've read through all of the Spring 3 Web docs: http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/spring-web.html but have been
I am writing an application in C#/WPF and am trying to figure out how
I've got an Enum called DoYouKnow, containing Yes , No and Unknown . I

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.