title: How do I put my SQL connection in a seperate class? C#
body: <p>I am using this to connect to my SQL-database.</p>
  
  <pre><code>namespace WindowsFormsApplication1
  {
      public partial class InvoiceGUI : Form
      {
          System.Data.SqlClient.SqlConnection con;
          System.Data.SqlClient.SqlDataAdapter da;
          DataSet ds1;
          DataRow dRow;
  
          int MaxRows = 0;
          int inc = 0;
  
          public InvoiceGUI()
          {
              InitializeComponent();
          }
  
          private void Form1_Load(object sender, EventArgs e)
          {
             con = new System.Data.SqlClient.SqlConnection();
             ds1 = new DataSet();
  
             con.ConnectionString = "Data Source=(local);Initial Catalog=invoice_db;Integrated Security=SSPI";
  
              con.Open();
              //MessageBox.Show("open");
  
              string sql = "select * from invoice";
              da = new System.Data.SqlClient.SqlDataAdapter(sql, con);
  
              da.Fill(ds1, "Invoice");
              NavigateInvoice();
  
              //Set the max rows
              MaxRows = ds1.Tables["Invoice"].Rows.Count;
  
              con.Close();
              //MessageBox.Show("closed");
  
          }
  </code></pre>
  
  <p>How do I move the connection to a separate class and how do I access my database from another class (Windows form)?<br>
  I guess it's best to have the the connection in one class and reach it from ex WindowsForm2</p>
  
  <p>Please give me an example</p>