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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:16:06+00:00 2026-06-15T12:16:06+00:00

I had entered some data in the TextBox and selected item in a combobox

  • 0

I had entered some data in the TextBox and selected item in a combobox in form2 and want to use same data in form1 how can I do so….
I tried this code
frmConfig is form2 and txtSrcIP is the TextBox

public partial class Form1 : Form
{    
    frmConfig f2 = new frmConfig();

    public Form1(frmConfig Cont)
    {
            f2 = Cont;
    }

    String SIp = f2.txtSrcIP.text;
}

The error is showing in this line String SIp = f2.txtSrcIP.text;
as A field initializer cannot reference the non static field method or property

frmConfig body
public partial class frmConfig : Form
{
private Form1 f1;

    public frmConfig()
    {
        InitializeComponent();
    }
    private void btnConnect_Click(object sender, EventArgs e)
    {



            // Open connection to the database
            string conString = "server="+txtSrcIP.Text+";uid="+txtSrcUserId.Text+";pwd="+txtSrcPwd.Text; 

            using (SqlConnection con = new SqlConnection(conString))
            {
                con.Open();

                // Set up a command with the given query and associate
                // this with the current connection.
                using (SqlCommand cmd = new SqlCommand("SELECT name from sys.databases", con))
                {
                    using (IDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            cbSrc.Items.Add(dr[0].ToString());
                        }
                    }
                }
            }

    private void btnNext_Click(object sender, EventArgs e)
    {
        if (cbSrc.SelectedItem != null && cbSrc.SelectedItem != "" && cbDest.SelectedItem != null && cbDest.SelectedItem != "")
        {

            this.Hide();
            //Form1 f1 = new Form1();
            f1.Show();

            this.Close();
        }
        else
        {
            MessageBox.Show("Enter all the details");
        }
    }

    }

this is what i am doing so i want all the textbox and combox value in form1

  • 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-06-15T12:16:07+00:00Added an answer on June 15, 2026 at 12:16 pm
    static frmConfig f2 = new frmConfig();
    

    So, how about these changes:

    public partial class Form1 : Form
    {    
        static frmConfig f2 = new frmConfig();
    
        public Form1(frmConfig Cont)
        {
            f2 = Cont;
        }
    
        public String SIp;
    }
    
    ...
    
    private void btnNext_Click(object sender, EventArgs e)
    {
        if (cbSrc.SelectedItem != null && cbSrc.SelectedItem != "" && cbDest.SelectedItem != null && cbDest.SelectedItem != "")
        {
    
            this.Hide();
            //Form1 f1 = new Form1();
            f1.SIp = f2.txtSrcIP.text;
            f1.Show();
    
            this.Close();
        }
        else
        {
            MessageBox.Show("Enter all the details");
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am returning some data from the database which is entered using many different
I had a phone number in which the entered data should be only numeric.
Had a good read through similar topics but I can't quite a) find one
Had a good search here but can't see anything that gets my mind in
I had a debate about macros and their readability. I think that in some
I'm new to web programming, but I had an idea I could use as
I have some problem in drupal registration page. I want to change whole user
I've noticed some strange browser specific weirdness with Google Chrome with some data bound
I am trying to get a Java desktop application to pull some data from
Can anyone suggest how I would do this: Say if I had the string

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.