title: Connect to an MDF Database
body: <p>In Visual Studio Form, Im creating a c# application. Im an trying to add data entered into a register form and save it into the MDF Database file i cretased with tables. But i cant connect to the database, Any Help?</p>
  
  <p>My Register Button Code when its clicked</p>
  
  <pre><code>private void CreateAccBtn_Click(object sender, EventArgs e)
  {
      string ConnectToDatabase = ("Data Source=  (LocalDB)\v11.0;AttachDbFilename=E:\\Work\\Information Systems      Development\\Game\\My Brain Cognitive Game\\My Brain Cognitive Game\\Brain Game Database.mdf;Integrated Security=True;Connect Timeout=10");
      SqlConnection ConnectDatabase = new SqlConnection(ConnectToDatabase);
      SqlCommand CMDDatabase = new SqlCommand("Insert Into Brain Game Database.User Table (User Name, Date Of Birth, Gender, Date Account Created, Condition, Email, Password) values('" + this.NewUsernameTxtBox.Text + "','" + this.DOBDateTimePicker3.Text + "','" + this.SexListBox1.Text + "','" + this.CurrentDatePicker1.Text + "','" + this.NewConditionTxtBox.Text + "','" + this.NewEmailTxtBox.Text + "','" + this.NewPasswordTxtBox.Text + "');",ConnectDatabase);
      SqlDataReader MyReader;
      try
      {
           ConnectDatabase.Open();
           MyReader = CMDDatabase.ExecuteReader();
           MessageBox.Show("Account Created");
           while (MyReader.Read())
           {
  
           }
      }
      catch (Exception ex)
      {
          MessageBox.Show(ex.Message);
      }
  }  
  </code></pre>