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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:29:46+00:00 2026-05-21T22:29:46+00:00

I have a combobox which is populated with various database name. I want to

  • 0

I have a combobox which is populated with various database name. I want to connect to a certain database on select of any database name from the combobox. Gow should I go about with this? The code for that is as follows..

private void Form1_Load(object sender, EventArgs e)   
      {  XmlDocument doc = new XmlDocument();
     doc.Load("C:\\Documents and Settings\\user\\Desktop\\abc.xml");             XmlNodeList List = doc.SelectNodes("config/dataSources/dataSource");    
         foreach (XmlNode dataSources in List)             
{ comboBox1.Items.Add(dataSources.Attributes["name"].Value.ToString());                    comboBox2.Items.Add(dataSources.Attributes["name"].Value.ToString());      
 }   

    } 

I have another code with connection string information

public class DBConnect   
  {        
 string dataSource;    
     string userId;      
   string password;        
 string filepath;          
public DBConnect()       
  {         }     
     public string ConnectionString()  
       {    filepath = ReadRegistry("ConfigFile");     
         XmlDocument doc = new XmlDocument();   
          doc.Load(@filepath);        
      XmlNodeList nodes = doc.SelectNodes
("/config/dataSources/dataSource");        
         foreach (XmlNode node in nodes)  
     {      if (userId.select == node.Attributes["dataSource"].Value)  
               {      dataSource = node.Attributes
["dataSource"].Value;                 
    userId = node.Attributes["userId"].Value;   
        password = node.Attributes["password"].Value;   
        password = Abc.Security.Encryption.Decode(password);
                     break;         

        }       
      }          
   string conn = "Provider=OraOLEDB.Oracle.1;Persist Security Info=False;Password=" + password + ";User ID=" + userId + ";Data Source=" + dataSource + ";";                 return conn;         }          protected string ReadRegistry(string filename)         {             Microsoft.Win32.RegistryKey theKey = Microsoft.Win32.Registry.LocalMachine;             theKey = theKey.OpenSubKey(@"SOFTWARE\Abc, Inc\Abc Marketing");              if (theKey != null)             {                 //string filePath = theKey.GetValue("ConfigFile").ToString();                 filepath = theKey.GetValue(filename).ToString();                 theKey.Close();           
  }    
          return filepath;  
       } 

So now how should I go about writing a code which on select of any database name from combobox connect me to that specific database. I am new to c# please suggest me a solution. Where should I be including the code?

  • 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-21T22:29:47+00:00Added an answer on May 21, 2026 at 10:29 pm

    Well, you can wire up your ComboBox’s SelectedIndexChanged event and when it fires you can retreive the selected database from the ComboBox’s SelectedItem property and use that in your connection string to connect to your database.

    Example
    You said you already have a working connection string. All you should need to do is allow your users to change the DataSource portion of that string. You can use the OracleConnectionStringBuilder.DataSource property to do this.

    Update this property in your ComboBox’s SelectedIndexChanged event:

    private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) {
        // A connection string for testing.
        string connectString = "Server=OracleDemo;Integrated Security=True"
        var builder = new OracleConnectionStringBuilder(connectString);
        // Show your connection string before any change.
        Console.WriteLine("ConnString before: {0}", builder.ConnectionString);
        builder.DataSource = comboBox1.SelectedItem.ToString();
        // This will show your conn string has been updated with the user selected database name.
        Console.WriteLine("ConnString  after: {0}", builder.ConnectionString);
    
        // At this point you're ready to use the updated connection string.
    }
    

    You’ll want to make your ComboBox use the DropDownStyle.DropDownList value so users can’t type in their own database names.

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

Sidebar

Related Questions

i have a combobox which is displaying date from database...in my database the date
I have a combobox which is populated by the Keys enumeration (winforms). The problem
I have a datagridview and a combobox which get populated randomly with data. However,
I have a combobox from which i need to programmatically disable items depending on
I have a combobox in winforms, which, depending on what you select, determines what's
I have a combobox which is connected to the database so I populate the
I have got ComboBox which is populated with collection of customTypes. On comboBox change,
I have a combobox where the user can select a particular year (populated by
I have a combobox which is populated by a binding source. I'm trying to
I have a ComboBox which is being populated by a LINQ query: var locations

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.