title: How to connect to SQL SERVER and insert data into database?
body: <p>I am trying to insert data into SQL SERVER 2008 using C#.
  When connecting, I followed this <a href="https://stackoverflow.com/q/17265068">solution</a>. When inserting data into database, used <a href="https://stackoverflow.com/a/11030203">this</a>. Result is data is not inserted into database. Problem is Visual Studio is not giving any errors. What can cause this?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>DateTime Start = DateTime.Now;
          List&lt;Point&gt; points = new List&lt;Point&gt;();
          System.Data.SqlClient.SqlConnection myConnection = new SqlConnection("server=localhost;" +
                                     "Trusted_Connection=yes;" +
                                     "database=UrbanPlan; " +
                                     "connection timeout=30");
          try
          {
              myConnection.Open();
              //here is giving successfull message
              Console.WriteLine("Successful");
          }
          catch (SqlException ex)
          {
              Console.WriteLine("You failed!" + ex.Message);
          }
  
          string csv_file_path = @"C:\Users\Joe\Desktop\geocoding.csv";
          DataTable csvData = GetDataTabletFromCSVFile(csv_file_path);
  
          int num = 0;
          while (num &lt; 10)
          {
              double longitude = Convert.ToDouble(csvData.Rows[num][1]);
              double latitude = Convert.ToDouble(csvData.Rows[num][2]);
  
              int numForCheck = 0;
              while (longitude != Convert.ToDouble(csvData.Rows[numForCheck][1]) &amp;&amp; latitude != Convert.ToDouble(csvData.Rows[numForCheck][2]))
              {
                  numForCheck++;
              }
  
              if (numForCheck == num)
              {
                  points.Add(new Point(longitude, latitude));
              }
              num++;
          }
  
          double eps = 1.0;
          int minPts = 2;
          List&lt;List&lt;Point&gt;&gt; clusters = GetClusters(points, eps, minPts);
          //Console.Clear();
          // print points to console
          Console.WriteLine("The {0} points are :\n", points.Count);
          foreach (Point p in points) Console.Write(" {0} ", p);
          Console.WriteLine();
          // print clusters to console
          int total = 0;
          for (int i = 0; i &lt; clusters.Count; i++)
          {
              int count = clusters[i].Count;
              total += count;
              string plural = (count != 1) ? "s" : "";
              Console.WriteLine("\nCluster {0} consists of the following {1} point{2} :\n", i + 1, count, plural);
              foreach (Point p in clusters[i])
              {
                  string sql = "INSERT INTO AntennaLocationByRegions (RegionId, Longitude, Latitude) values (@RegionId, @Longitude, @Latitude)";
                  SqlCommand cmd = new SqlCommand(sql, myConnection);
                  cmd.Parameters.Add("@RegionId", SqlDbType.Int);
                  cmd.Parameters["@RegionId"].Value = i + 1;
                  cmd.Parameters.Add("@Longitude", SqlDbType.Float);
                  cmd.Parameters["@Longitude"].Value = p.Long;
                  cmd.Parameters.Add("@Latitude", SqlDbType.Float);
                  cmd.Parameters["@Latitude"].Value = p.Lat;
                  cmd.ExecuteNonQuery();
              }
              Console.WriteLine();
          }
  </code></pre>