title: Foreach Loop is not Working properly
body: <p>There is problem in this code when I use parameterized query  loop get one file name in  <code>string filename = Path.GetFileName(item);</code> variable again and again</p>
  
  <pre><code> string[] filePaths = Directory.GetFiles(Server.MapPath("~/Gallery/GalleryImage/" + newtable));
  
  
      int a = 0;
  
      OleDbCommand cmd = new OleDbCommand();
  
      OleDbConnection mycon = new OleDbConnection();
  
      mycon.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\AGENTJ.AGENTJ-PC\Documents\Visual Studio 2010\WebSites\mfaridalam\App_Data\mfaridalam1.accdb";
  
      cmd = mycon.CreateCommand();
  
      mycon.Open();
  
      DateTime dateTime = DateTime.UtcNow.Date;
      foreach (string item in filePaths)
      {
          a++;
          string filename = Path.GetFileName(item);
          string ips = "00" + a.ToString();
  
         // Response.Write("Number (" + a.ToString() + ")    " + filename + "    " + ips + "    " + t1 + "     " + v + "     " + some + "   " + some + "&lt;br/&gt;&lt;br/&gt;");
  
         // cmd.CommandText = "INSERT INTO [Image] ([Image],[Sort],[Created],[Albumid],[Description],[title])VALUES('" + filename + "','" + ips + "','" + dateTime.ToString("dd/MM/yyyy") + "','" + newtable + "','" + TextBox4.Text + "','" + TextBox3.Text + "')";
          cmd.CommandText = "INSERT INTO [Image] ([Image],[Sort],[Created],[Albumid],[Description],[title])VALUES (?,?,?,?,?,?)";
          cmd.Parameters.AddWithValue("@p1", filename);
          cmd.Parameters.AddWithValue("@p2", ips);
          cmd.Parameters.AddWithValue("@p3", dateTime.ToString("dd/MM/yyyy"));
          cmd.Parameters.AddWithValue("@p4", newtable);
          cmd.Parameters.AddWithValue("@p5", TextBox4.Text);
          cmd.Parameters.AddWithValue("@p6", TextBox3.Text);
          cmd.ExecuteNonQuery();
      }
  </code></pre>
  
  <p>But when I use normal insert query </p>
  
  <pre><code>     cmd.CommandText = "INSERT INTO [Image] ([Image],[Sort],[Created],[Albumid],[Description],[title])VALUES('" + filename + "','" + ips + "','" + dateTime.ToString("dd/MM/yyyy") + "','" + newtable + "','" + TextBox4.Text + "','" + TextBox3.Text + "')";
  </code></pre>
  
  <p>loop is working alright and get all the name of files at specific location. Please let me know why ?Is there any problem in my logic ?</p>