title: DataGrid binding with sql server database
body: <p>I am simply binding a database table with datagrid. I am getting this excption 
  "Exception has been thrown by the target of an invocation." I have google it but didn't able to find the reason. what I am doing wrong? Or is this due to some other factor? </p>
  
  <p>here is my code.
  In XAML</p>
  
  <pre><code> &lt;DataGrid Name="data_grid"  AutoGenerateColumns="True"/&gt;
  </code></pre>
  
  <p>In .cs</p>
  
  <pre><code>SqlConnection cn = new SqlConnection(getString());
          cn.Open();
          SqlCommand cmd = new SqlCommand("Select * from data", cn);
          DataSet ds = new DataSet();
          SqlDataAdapter adpp = new SqlDataAdapter(cmd);
          adpp.Fill(ds);
          data_grid.DataContext = ds;
          cn.Close();
  </code></pre>
  
  <p>Instead of dataset I have also try by using datatable.</p>
  
  <pre><code>datatable dt = new datatable;
  adpp.Fill(dt);
  data_grid.ItemsSource = dt.DefaultView;
  </code></pre>
  
  <p>I have debug it. I got exception on function where I getting connectionstring from app1.config.</p>
  
  <pre><code>public string getString() {
             return ConfigurationManager.ConnectionStrings["myconnection"].ConnectionString.ToString();
  
       }
  </code></pre>
  
  <p>and the app1.config code is</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;connectionStrings&gt;
      &lt;add name="myconnection" connectionString="Data Source=.\sqlexpress;Initial Catalog=daniwpf;Integrated Security=True"/&gt;
    &lt;/connectionStrings&gt;
  &lt;/configuration&gt;
  </code></pre>