title: Best method to connect to SQL Server in C# WPF
body: <p>I'm a beginner.</p>
  
  <p>I already found a way to connect to SQL SERVER using the codes below:</p>
  
  <pre><code>private void getListBtn_Click(object sender, RoutedEventArgs e)
      {
          SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=myDB;Integrated Security=true;");
          SqlDataAdapter sda = new SqlDataAdapter("SELECT ID,Date,Name,City FROM Info;", con);
          DataTable dt = new DataTable();
          sda.Fill(dt);
          dataGridForm.ItemsSource = dt.DefaultView;
  </code></pre>
  
  <p>I also wanted to get number of rows from a TABLE and set it to a label, But it's not a good idea to copy and paste this code again, I want to have a method for sqlconnection so i won't rewrite this code again and again for every single query.</p>
  
  <p>Sorry i'm an absolute beginner, 3 days since i started learning C# WPF.</p>