title: c# : How to get data from database and pass to another form?
body: <p>I'm building a desktop application where when a used logged it in new his Id will be appeared in textBox. But in my case query run successfully but id doesn't appear in textBox..can anyone help me to find it out please?</p>
  
  <p>First form of User logged in (Form1.cs)</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Data.SqlClient;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  
  namespace EmployeeApp
  {
      public partial class login : Form
      {
          public login()
          {
              InitializeComponent();
          }
  
          public string employeeID;
          private void exitButton_Click(object sender, EventArgs e)
          {
              this.Close();
          }
          private void loginButton_Click(object sender, EventArgs e)
          {
              SqlConnection connection = new SqlConnection(@"Data Source=INCEPSYS-SE\TEST;Initial Catalog=Employee;Integrated Security=True");
              connection.Open();
              String query = "select * from Employees where Name = '" + nameTextBox.Text + " ' and Password = '" + passwordTextBox.Text + "'";
  
              SqlCommand command = new SqlCommand(query, connection);
              SqlDataReader myReader = command.ExecuteReader();
              while (myReader.Read())
              {
                  string employeeID = myReader["EmployeeID"].ToString();
              }
              myReader.Close();
              SqlDataAdapter sda  = new SqlDataAdapter(query,connection);            
              connection.Close();
              DataTable dt = new DataTable();
              sda.Fill(dt);
                  if (dt.Rows.Count == 1)
              {
                  this.Hide();
                  Entry ss = new Entry(employeeID);
                  ss.Show();
              }
              else
              {
                  MessageBox.Show("Please Check your Username &amp; password");
              }
          }
  
      }
  }
  </code></pre>
  
  <p>Second form (Entry.cs)</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Windows.Forms;
  
  namespace EmployeeApp
  {
      public partial class Entry : Form
      {
          public Entry()
          {
              InitializeComponent();
          }
          public Entry(string employeeId)
          {
                InitializeComponent();
                idTextBox.Text = employeeId;
          }
  
  
         private void reportButton_Click(object sender, EventArgs e)
          {
              Report report = new Report();
              report.Show();
          }
      }
  }
  </code></pre>