title: Inserting data to a Database Visual Studio
body: <p>I am trying to insert data into a database using service-based Database I am using Visual Studio 2010. I have created the table but it doesn't work here is my code:
  I would appreciate if you have suggestion of code how to insert to a database.</p>
  
  <pre><code>public void AddAnimal(int animalID, string name, double age, string category, string gender, string extraAnimalInfo)
      {
          using (SqlConnection con = new SqlConnection(DBAccessLayer.Properties.Settings.Default.AnimalDBConnectionString))
          {
              con.Open();
              try
              {
                  using (SqlCommand command = new SqlCommand("INSERT INTO AnimalTable VALUES(@AnimalID, @Name, @Age, @Category, @Gender, @ExtraAnimalInfo)", con))
                  {
                      Console.WriteLine("Here 4");
                      command.Parameters.Add(new SqlParameter("AnimalID", animalID));
                      command.Parameters.Add(new SqlParameter("Name", name));
                      command.Parameters.Add(new SqlParameter("Age", age));
                      command.Parameters.Add(new SqlParameter("Category", category));
                      command.Parameters.Add(new SqlParameter("Gender", gender));
                      command.Parameters.Add(new SqlParameter("ExtraAnimalInfo", extraAnimalInfo));
                      command.ExecuteNonQuery();
                  }
              }
              catch (Exception ex)
              {
                  Console.WriteLine("Could not insert.");
              }
          }
  </code></pre>
  
  <p><strong>UPDATE1:</strong>
  When I insert the data into the database the rows are affected but When I open the database table from the Server Explorer nothing have changed.</p>
  
  <hr>
  
  <p>When I insert the data into the database the rows are affected but When I open the database table from the Server Explorer I don't see any changes.</p>