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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T05:37:14+00:00 2026-05-18T05:37:14+00:00

I have to call a function on a button click event like this private

  • 0

I have to call a function on a button click event like this

private void btnConnect_Click(object sender, EventArgs e)
{
    string localHost = "192.168.10.3";
    string logInDetails = "gp";

    //SqlConnection sConnection = new 
    //SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
    try
    {
        //Checking for the Valid entries in textboxes.
        if ((txtPassword.Text == logInDetails) && (txtUsername.Text == logInDetails))
        //Checking for the appropriate local server address.
        if (txtHost.Text == localHost)
        {
             BindDBDropDown();
             SetOperationDropDown();
             PrimaryKeyTable();
             lblError.Text = "You are connected to the SQL Server....";
        }
        else
        {
             lblError.Text = "Invalid Credentials";
        }

        }
        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
        //{
        //    //To close the connection
        //    if (sConnection != null)
        //    {
        //        sConnection.Close();
        //    }
        //}
    }

the BindDBDropDown function definition is in separate class like

public class DataAccessMaster
{

   /// <summary>
   /// This function gets the list of all the databases present in the local server.
   /// </summary>
   /// <returns></returns>
    public static DataSet GetAllDataBaseNames()
    {
        SqlConnection sConnection = new
          SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
        //To Open the connection.
        sConnection.Open();

        string selectDatabase = @"SELECT   
                                        [NAME]
                                    FROM     
                                        [master..sysdatabases]";

        SqlCommand sCommand = new SqlCommand(selectDatabase, sConnection);

        try
        {

            DataSet dsListOfDatabases = new DataSet("master..sysdatabases");
            SqlDataAdapter da = new SqlDataAdapter(selectDatabase, sConnection);
            da.TableMappings.Add("Table", "master..sysdatabases");
            da.Fill(dsListOfDatabases);

            DataViewManager dsv = dsListOfDatabases.DefaultViewManager;
            return dsListOfDatabases;
        }
        catch (Exception ex)
        {
            EventLog log = new EventLog("Application");
            log.Source = "MFDBAnalyser";
            log.WriteEntry(ex.Message);
            return null;
        }

        finally
       {
            //To close the connection
        if(sConnection != null)
            {
                sConnection.Close();
            }
       }

and I called this function like this

    public void BindDBDropDown()
    {
        DataSet dsDatabaseList = default(DataSet);

        try
        {
            //The function GetAllDataBaseNames() is called from the DataAccessMaster class.
            dsDatabaseList = DataAccessMaster.GetAllDataBaseNames();

            //Path to the combo box is given to get the value through the   GetAllDataBaseNames().
            cmbDatabases.DataSource = dsDatabaseList.Tables["master..sysdatabases"];
            cmbDatabases.DisplayMember = "NAME";
            cmbDatabases.ValueMember = ("");
        }

But it is not binding the required list in the drop down.
Can you guys plz 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-18T05:37:15+00:00Added an answer on May 18, 2026 at 5:37 am

    I’m guessing the problem is largely here:

        catch (Exception ex)
        {
            EventLog log = new EventLog("Application");
            log.Source = "MFDBAnalyser";
            log.WriteEntry(ex.Message);
            return null;
        }
    

    If anything goes wrong, you are swallowing it (returning null). You don’t show what the catch is in BindDBDropDown, but I’m guessing it is similar…

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

Sidebar

Related Questions

I have a JavaScript function, pop_item . I have to call this from PHP,
I have this function: RegisterGlobalHotKey(Keys.F6, MOD_SHIFT | MOD_CONTROL); which call an API to register
asp:Button inside SharePoint Dataview Rows with onclick event does not call C# function. Pull
I have one link button with a click event. When Clicked I want to
Is there any way to have PHP automatically call a function, before a script
I have a wrapper around a C++ function call which I call from C#
So i have a piece of assembly that needs to call a function with
I want to call a c# function from my javascript function. I have a
I have a simple function that I want to call in the code behind
I have got a C function in a static library, let's call it 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.