title: SQL Insert query is executed twice
body: <p>I'm using <a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqldataadapter.InsertCommand.aspx" rel="nofollow noreferrer">adapter.InsertCommand</a> to insert some data into a table.</p>
  
  <p>The only problem is that it's executed twice, thus giving me double entries in the DB.
  I've tried following the example in the documentation of <code>adapter.InsertCommand</code> and my own code, but get the same result.</p>
  
  <p>This is my code:</p>
  
  <pre><code>public class nokernokDAL
  {
      SqlConnection connection = new SqlConnection();
      SqlDataAdapter adapter = new SqlDataAdapter();
  
      public nokernokDAL()
      {
          connection.ConnectionString = EPiServer.Global.EPConfig["EPsConnection"].ToString();
          connection.Open();
      }
  
      public void addNewComment(int userID, int pageID, string title, string comment)
      {
          string query = "INSERT INTO dbo.nokernok_kommentarer (userID, pageID, commentTitle, comment) " +
                         "VALUES ("+ userID +", "+ pageID +", '"+ title +"', '"+ comment +"')";
  
          adapter.InsertCommand = new SqlCommand(query, connection);
          adapter.InsertCommand.ExecuteNonQuery();
  
      }
  }
  </code></pre>
  
  <p>Anny suggestions in how I can avoid this?</p>
  
  <p><strong>UPDATE</strong>  </p>
  
  <p>Right, after some debugging, I discovered that my <code>newWallComplaint_Click</code> function was fired twice. This was becuae I had the following code:</p>
  
  <pre><code>    protected void Page_Load(object sender, EventArgs e)
      {
              btnNewWallComplaint.Click += new EventHandler(this.newWallComplaint_Click);
      }
  </code></pre>
  
  <p>Not checking for PostBack, this executes my function after submit also. So to avoid having my function run twice, I added a check for PostBack.</p>
  
  <pre><code>    protected void Page_Load(object sender, EventArgs e)
      {
          if (!IsPostBack)
          {
              btnNewWallComplaint.Click += new EventHandler(this.newWallComplaint_Click);
          }
  
      }
  </code></pre>
  
  <p>Now my query is not run twice.</p>