title: C# How do I get data from Database to textboxes
body: <p>Greetings programmers,</p>
  
  <p>I have a combobox and some textboxes in my windows form connected to a database. My idea is, when the value of the combobox changes the data in the textboxes changes too. Like when I pick a customer ID in the combobox, the textboxes will be loaded with the data of the customer, like the Full name or the address etc. But when I open the Form the combobox disapear's and the textboxes stays empty. I am using Access database and Visual Studio 2012 to code. Here is my code..</p>
  
  <p><strong>C# code</strong>:</p>
  
  <pre><code>private void comboBox1_SelectedValueChanged(object sender, EventArgs e)
      {
          string pc = Convert.ToString(comboBox1.SelectedValue);
          string sql = "SELECT * FROM Customer WHERE CustomerID="+ pc;
          Data.Customer_Data(sql, pc);
  
          txtfullname.Text = Data.fullname;
          txtadress.Text = Data.adress;
          txtcity.Text = Data.city;
          txtemail.Text = Data.email;
  
      }
  </code></pre>
  
  <p>And my class called Data:</p>
  
  <pre><code>public static string cs = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Application.StartupPath + "\\Database1.accdb";
  public static string fullname = "";
  public static string adress = "";
  public static string city = "";
  public static string email = "";
  public static void Customer_Data(string sql, string pc)
      {
              if (pc == "")
              {
                  return;
              }
  
              else
              {
                  OleDbConnection oleDbConnection1 = new System.Data.OleDb.OleDbConnection(cs);
                  oleDbConnection1.Open();
                  OleDbCommand oleDbCommand1 = new System.Data.OleDb.OleDbCommand(sql,oleDbConnection1);
                  OleDbDataReader reader = oleDbCommand1.ExecuteReader();
  
                  if (!reader.Read())
                      return;
  
                  fullname = reader["fullname"].ToString();
                  adress = reader["adress"].ToString();
                  city = reader["city"].ToString();
                  email = reader["email"].ToString();
  
  
                  oleDbConnection1.Close();
              }
      }
  </code></pre>