title: Does instantiating a DataSet object automatically create a connection to a SQL service-based database for CRUD operations?
body: <p>Here is everything that I did:</p>
  
  <ol>
  <li><p>In a visual studio 2013 C# project, I created a service database (.mdf file). Note: I changed the name from Database1.mdf to fghLocalDB.mdf.
  <img src="https://i.stack.imgur.com/e4krX.png" alt="enter image description here"></p></li>
  <li><p>I opened this database in the server explorer.</p></li>
  <li><p>I created 2 tables called Country and CarbonDioxide using the table designer.
  <img src="https://i.stack.imgur.com/tN0Hv.png" alt="enter image description here"></p></li>
  <li><p>I added an entry to the Country table as shown by the Data Table of the Country table.
  <img src="https://i.stack.imgur.com/f0lQa.png" alt="enter image description here"></p></li>
  <li><p>I did the following to create a DataSet my application can use. I created a Data Source by clicking on the "Project" option on the top menu bar and clicking on the "Add New Data Source ..." option from the drop down. 
  <img src="https://i.stack.imgur.com/KNiKf.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/H74vi.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/xiqxS.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/ZcT4R.png" alt="enter image description here"></p></li>
  <li><p>This is what my project files looked like at this point.
  <img src="https://i.stack.imgur.com/xDsOp.png" alt="enter image description here"></p></li>
  <li><p>I wrote the following code in the main method thinking that this would be all I need to write to the database.</p>
  
  <pre><code>// Create a connection to the DataSet and TableAdapters that will communicate with our 
  // local database to handle CRUD operations.
  
  
  fghLocalDBDataSet dataSet = new fghLocalDBDataSet();
  fghLocalDBDataSetTableAdapters.CountryTableAdapter countryTableAdapter = 
  new fghLocalDBDataSetTableAdapters.CountryTableAdapter();
  
  try
  {
     // Insert a row into Country table. EDIT 1 Will comment after first program run.
     Console.WriteLine(countryTableAdapter.Insert("United States"));
  
     // Actually writeback information to the database?      
     // dataSet.AcceptChanges(); EDIT 2 commented this as LeY suggested it was not needed.
  
  
     // EDIT 3 Validation code as suggested by Ley.
     var dt = new fghLocalDBDataSet.CountryDataTable();
     var adapter = new fghLocalDBDataSetTableAdapters.CountryTableAdapter();
     adapter.Fill(dt);
  
     foreach (var row in dt)
     {
              // This does not get executed after a second run of the program.        
              // Nothing is printed to the screen.
              Console.WriteLine("Id:" + row.Id + "----Name: " + row.Name);
     }
     Console.Read();
  }
  catch(SqlException exception){
     Console.WriteLine("ERROR: " + exception.ToString());
  }
  Console.ReadLine();
  </code></pre></li>
  <li><p>I ran the program and everything seemed fine.</p></li>
  <li>I opened the tables by right clicking on these tables in the server explorer and pressing "Show Data Table".</li>
  <li>The "United States" row was not added as wanted.</li>
  <li><p>I think it has to do with the connectionstring. I right clicked on my project and opened properties. 
  <img src="https://i.stack.imgur.com/ng2iT.png" alt="enter image description here">
  <img src="https://i.stack.imgur.com/aXdtq.png" alt="enter image description here"></p></li>
  <li><p>Here I made sure the connection string matched that of the local database by looking at the string in the properties of the database. They are the same.
  <img src="https://i.stack.imgur.com/TwqqK.png" alt="enter image description here"></p></li>
  </ol>
  
  <p>I copied and pasted the actual text for each connection string:</p>
  
  <p>Connection string of project: </p>
  
  <p>Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\fghLocalDB.mdf;Integrated Security=True</p>
  
  <p>Connection string of actual database (.mdf file):</p>
  
  <p>Data Source=(LocalDB)\v11.0;AttachDbFilename=C:\Users\gabriel\Source\Workspaces\Capstone\Sandbox\aduclos\QueryDataMarketConsole\QueryDataMarketConsole\fghLocalDB.mdf;Integrated Security=True</p>
  
  <p>I am assuming |DataDirectory| is equal to C:\Users\gabriel\Source\Workspaces\Capstone\Sandbox\aduclos\QueryDataMarketConsole\QueryDataMarketConsole\fghLocalDB.mdf; since in the picture above when I clicked on the button to expand the Value of the connection string the connection properties window opened up and had this path for the database file name.</p>
  
  <p>My question in a nutshell is does instantiating a DataSet object in the code automatically create a connection to a SQL service-based database for CRUD operations?</p>
  
  <p>If not how do I connect my DataSet object to my sql database so that way I can actually write to the database when using the TableAdapters?</p>
  
  <p>I read the following links:</p>
  
  <p><a href="https://stackoverflow.com/questions/4550437/insert-method-of-tableadapter-not-working">Insert method of TableAdapter not working?</a></p>
  
  <p><a href="https://stackoverflow.com/questions/19873241/tableadapter-insert-not-persisting-data">TableAdapter Insert not persisting data</a></p>
  
  <p><a href="https://stackoverflow.com/questions/5316957/use-connectionstring-from-web-config-in-source-code-file">Use connectionstring from web.config in source code file</a></p>
  
  <p>Do I need an actual SqlConnection object? and how to I connect this to the DataSet &amp; TableAdapters?</p>