title: ASP.net form SQL Server update from inputbox
body: <p>I'm trying to update a table in my SQL Server database with text from an input box on my site; </p>
  
  <p>My table is <code>MemberSite.dbo.Users</code> and the columns within this table are: </p>
  
  <pre><code>ID (Auto incrementing) UserName, Password, ApiKey, VeriF
  </code></pre>
  
  <p>It's not updating my SQL Server table.</p>
  
  <p>What I want this to do: take the input text and put it in my SQL Server table against the user that is logged in. </p>
  
  <p>Here is some code <code>web.config</code> : </p>
  
  <pre><code>&lt;add name="WRITER" 
       connectionString="Data Source=localhost;Initial Catalog=MembershipSite;User ID=test;Password=test!" 
       providerName="System.Data.SqlClient" /&gt;
  </code></pre>
  
  <p>Backend to button click;</p>
  
  <pre><code>protected void Save_Click(object sender, EventArgs e)
  {
      SqlConnection conn = null;
  
      try
      {
          string sql = "UPDATE dbo.Users SET ApiKey = @API, VeriF = @verif WHERE UserName = @username";
  
          conn = new SqlConnection(ConfigurationManager.ConnectionStrings["WRITER"].ConnectionString);
  
          SqlCommand cmd = new SqlCommand(sql, conn);
  
          SqlParameter api = new SqlParameter();
          api.ParameterName = "@API";
          api.Value = APIinput;
          cmd.Parameters.Add(api);
  
          SqlParameter verif = new SqlParameter();
          verif.ParameterName = "@verif";
          verif.Value = Veri;
          cmd.Parameters.Add(verif);
  
          SqlParameter UserN = new SqlParameter();
          UserN.ParameterName = "@username";
          UserN.Value = User.Identity.Name;
          cmd.Parameters.Add(UserN);
  
          conn.Open();
      }
      finally
      {
          if (conn !=null)
              conn.Close();
      }
  }
  </code></pre>