title: Can select from but not insert into database mysql C# ASP.NET
body: <p>I have a connection to my db and I can retrieve data no problem but I'm unable to insert. The alert also isn't being displayed so I'm sure the query isn't being executed and it's just redirecting to the aspx page. I've tried many different solutions but I assume the problem is not where I'm looking. Here's the code, I hope someone can help. </p>
  
  <p>Code behind:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using System.IO;
  using System.Data.SqlClient;
  using System.Configuration;
  using System.Data;
  using System.Threading;
  using System.Threading.Tasks;
  
  namespace Childrens.Admin
  {
  public partial class WebForm1 : System.Web.UI.Page
  {
      protected void btnViewStaff_ServerClick(object sender, EventArgs e)
      {
          divAddStaff.Visible = false;
          staffGridView.Visible = true;
      }
  
      protected void btnAddNewStaff_ServerClick(object sender, EventArgs e)
      {
          staffGridView.Visible = false;
          divAddStaff.Visible = true;
      }
  
      protected void btnSubmitStaff_ServerClick(object sender, EventArgs e)
      {
          if (txtPassword == txtCPassword)
          {
              using (SqlConnection addStaffConn = new SqlConnection(ConfigurationManager.ConnectionStrings["myConn"].ToString()))
              {
                  try
                  {
                      addStaffConn.Open();
  
                      string query = "INSERT INTO [Staff] (staff_fname,staff_sname,staff_email,staff_pass) VALUES ('" + txtFName + "','" + txtSName + "','" + txtEmail + "','" + txtPassword+"')"; //(@fname,@sname,@email,@pass)";
                      SqlDataAdapter staffAdapter = new SqlDataAdapter();
                      SqlCommand addStaffCommand = new SqlCommand(query, addStaffConn);
  
                      /*addStaffCommand.Parameters.AddWithValue("@fname", txtFName);
                      addStaffCommand.Parameters.AddWithValue("@sname", txtSName);
                      addStaffCommand.Parameters.AddWithValue("@email", txtEmail);
                      addStaffCommand.Parameters.AddWithValue("@pass", txtPassword);*/
                      staffAdapter.InsertCommand = addStaffCommand;
                      staffAdapter.InsertCommand.ExecuteNonQuery();
  
  
                      addStaffConn.Close();
                      Response.Write(String.Format("&lt;script&gt;alert('The entry was successful!');window.location='{0}';&lt;/script&gt;", "URL=staff.aspx"));
  
                  }
                  catch (Exception ex)
                  {
                      Response.Write(String.Format("&lt;script&gt;alert('The entry was successful!');window.location='{0}';&lt;/script&gt;", "URL=staff.aspx"));
                  }
                  finally
                  {
                      if (addStaffConn.State == System.Data.ConnectionState.Open)
                      {
                          addStaffConn.Close();
                      }
                      addStaffConn.Dispose();
                  }
              }
          }
      }
  }
  }
  </code></pre>
  
  <p>web.config file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  
  &lt;!--
  For more information on how to configure your ASP.NET application, please 
  visit
  https://go.microsoft.com/fwlink/?LinkId=169433
  --&gt;
  &lt;configuration&gt;
  &lt;appSettings&gt;
      &lt;add key="ValidationSettings:UnobtrusiveValidationMode" value="None" /&gt;
  &lt;/appSettings&gt;
  &lt;system.web&gt;
  &lt;compilation debug="true" targetFramework="4.6.1"/&gt;
  &lt;httpRuntime targetFramework="4.6.1"/&gt;
  &lt;/system.web&gt;
  &lt;system.codedom&gt;
  &lt;compilers&gt;
    &lt;compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/&gt;
    &lt;compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
      type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, 
     Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.8.0, 
  Culture=neutral, PublicKeyToken=31bf3856ad364e35"
      warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 
  /define:_MYTYPE=\&amp;quot;Web\&amp;quot; /optionInfer+"/&gt;
  &lt;/compilers&gt;
  &lt;/system.codedom&gt;
  &lt;connectionStrings&gt;
  &lt;add name="myConn" connectionString="server=localhost;user 
  id=root;persistsecurityinfo=True;database=childrens" /&gt;
  &lt;add name="childrensConnectionString" 
  connectionString="server=localhost;user id=root;password=password;persistsecurityinfo=True;database=childrens;allowuservariables=True"
      providerName="MySql.Data.MySqlClient" /&gt;
   &lt;/connectionStrings&gt;
  
   &lt;/configuration&gt;
  </code></pre>