title: binding datagrid for Wpf to a DB
body: <p>I am trying bind a DataGrid for WPF to a table in MS SQL Database.</p>
  
  <p>1) First I created a App.config file as followsrrr</p>
  
  <pre><code>    &lt;connectionStrings&gt; 
        &lt;add name="ConString" connectionString="Data Source=MYDataSB\SQLExpress; 
         User Id=sa;Password=gm03C3; Initial Catalog=MYDB;"&gt;
      &lt;connectionStrings/&gt;
  </code></pre>
  
  <p>2) Secondly, I added a datagrid to my Form with a name grdEventLog</p>
  
  <pre><code>      &lt;Grid&gt;
          &lt;DataGrid Name="grdEventLog"/&gt;
        &lt;/Grid&gt;
  </code></pre>
  
  <p>3) then I added this code to MainWindow.xaml.cs file as follows:</p>
  
  <pre><code>     using System.Data;
       using System.Data.SqlClient;
       using System.Web;
  
  public partial class MainWindow : Window
  {
      public MainWindow()
      {
          InitializeComponent();
          FillDataGrid();
      }
  
      private void FillDataGrid()
      {
          string ConString = ConfigurationManager.ConnectionStrings["ConString"].ConnectionString;
          string CmdString = string.Empty;
          using (SqlConnection con = new SqlConnection(ConString))
          {
              CmdString = "SELECT Server,Date,Typ,Msg FROM EventLog";
              SqlCommand cmd = new SqlCommand(CmdString, con);
              SqlDataAdapter sda = new SqlDataAdapter(cmd);
              DataTable dt = new DataTable("EventLog");
              sda.Fill(dt);
              grdEventLog.ItemsSource = dt.DefaultView;
          }
      }
  </code></pre>
  
  <p>After typing all these entries, I have the error at  ConfigurationManager stating "The name does not exist in the current context"</p>
  
  <p>I am trying to add reference cfgmgr32.dll to overcome this error. But it is not being accepted. Can anyone suggest to over come this error ?!</p>
  
  <p>Alternative suggestion for approaching databinding in WPF is also welcome.</p>