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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:08:31+00:00 2026-05-18T20:08:31+00:00

I have a function like this defined in one class: using System; using System.Collections.Generic;

  • 0

I have a function like this defined in one class:

using System;
using System.Collections.Generic;

using System.Linq;
using System.Text;

using System.Data;
using System.Data.SqlClient;

using System.Windows.Forms;
using System.Configuration;
using System.Diagnostics;
using MFDBAnalyser;

namespace MFDBAnalyser

{

    public class DataAccessMaster:MFDBAnalyser

    {


        //        /// <summary>
        //        /// This function gets the list of all the databases present in the local server.
        //        /// </summary>
        //        /// <returns></returns>


        public static DataSet GetAllDataBaseNames()

        {

            SqlConnectionStringBuilder objConnectionString = new SqlConnectionStringBuilder();
            objConnectionString.DataSource = txtHost.Text;
            objConnectionString.UserID = txtUsername.Text;
            objConnectionString.Password = txtPassword.Text;

            SqlConnection sConnection = new SqlConnection(objConnectionString.ConnectionString);

            //If connected then give this message to user
            lblMessage.Visible = true;
            lblMessage.Text = "You are connected to the SQL Server....";

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

                //Query to select the list of databases.
                string selectDatabaseNames = @"SELECT 
                                                    NAME 
                                                 FROM 
                                                    [MASTER]..[SYSDATABASES]";

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

                //Create the data set 
                DataSet sDataset = new DataSet("master..sysdatabases");

                //Create the dataadapter object
                SqlDataAdapter sDataAdapter = new SqlDataAdapter(selectDatabaseNames, sConnection);
                sDataAdapter.TableMappings.Add("Table", "master..sysdatabases");

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

                //Bind the database names in combobox
                DataViewManager dsv = sDataset.DefaultViewManager;

            }
            catch(Exception ex)
            {
                //All the exceptions are handled and written in the EventLog.
                EventLog logException = new EventLog("Application");
                logException.Source = "MFDBAnalyser";
                logException.WriteEntry(ex.Message);
                MessageBox.Show("Login Failed!!", "Error Occured");
            }
            finally
            {
                //If connection is not closed then close the connection
                if(sConnection.State != ConnectionState.Closed)
                {
                    sConnection.Close();
                }
            }
        }
    }
}

And then I called this function in another class like this:

public void BindDBDropDown()

        {

 DataSet dsTablesWithoutForeignKeys = default(DataSet);

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

                cmbDatabases.DisplayMember = "TABLE_NAME";
                cmbDatabases.ValueMember = "";
                cmbDatabases.DataSource = dsTablesWithoutForeignKeys.Tables["master..sysdatabases"];
            }
            catch(Exception ex)
            {
                //All the exceptions are handled and written in the EventLog.
                EventLog logException = new EventLog("Application");
                logException.Source = "MFDBAnalyser";
                logException.WriteEntry(ex.Message);
            }
        }

But there is showing a error like txtHost etx doesn’t exist and when I change the protected modifier of designer.cs class to public then also it is showing error…

Can anybody tell me whats is happening??

  • 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-18T20:08:32+00:00Added an answer on May 18, 2026 at 8:08 pm

    Assuming that your text boxes are defined in MFDBAnayser class, you still will not be able to access them in your GetAllDataBaseNames function. GetAllDataBaseNames is a static function and therefore it will not be able to access instance variables like the text boxes or other controls.

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

Sidebar

Related Questions

Assume I have a function template like this: template<class T> inline void doStuff(T* arr)
I have a function that looks like this class NSNode { function insertAfter(NSNode $node)
Ok, I have one JavaScript that creates rows in a table like this: function
I have a function that looks something like this: //iteration over scales foreach ($surveyScales
So I have a function that looks something like this: float function(){ float x
I have a function that I use to add vectors, like this: public static
I have multiple setTimeout functions like this: function bigtomedium(visiblespan) { visiblespan.removeClass('big').addClass('medium'); setTimeout(function(){ mediumtosmall(visiblespan);},150); };
So I have something like this: var xmlStatement:String = xmlObject.node[3].@thisValue; What mystery function do
I have a string that looks like this: Name1=Value1;Name2=Value2;Name3=Value3 Is there a built-in class/function
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>

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.