title: Update the mysql database using Asp.Net
body: <p>Here I got a web form I used select Query and displayed it a form and i need it to update using Query I tried lost of method. I couldn't update,it just updating but passing the old value instead of new changed value.</p>
  
  <pre><code>Here is the form 
  
  
  
  &lt;%@ Page Language="C#" AutoEventWireup="true" CodeFile="Editcar.aspx.cs" MasterPageFile="MasterPage2.master" Inherits ="Editcar" %&gt;
  &lt;asp:Content ID="formContent" ContentPlaceHolderID="ContentPlaceHolder1" runat="server"&gt;
  
  
   &lt;form id="form1" runat="server" class="col-md-10" methode="post" &gt;
  
  
      &lt;asp:Table ID="GridView1" class="nav-justified" runat="server" AutoGenerateColumns="false" Height="628px" Width="763px"&gt;
          &lt;asp:TableRow&gt;
             &lt;asp:TableCell&gt;
                  &lt;h4&gt; Car name:&lt;/h4&gt;
  
             &lt;/asp:TableCell&gt;
             &lt;asp:TableCell&gt;
                  &lt;asp:TextBox ID="id" runat="server" name="id" Width="301px" Text='&lt;%# Eval("id") %&gt;' Visible="False" CssClass="form-control"&gt;&lt;/asp:TextBox&gt;
                  &lt;asp:TextBox ID="carmake" runat="server" Font-Names="carmake" Width="301px" Text='&lt;%#  Eval("car_make") %&gt;' CssClass="form-control"&gt;&lt;/asp:TextBox&gt;
  
             &lt;/asp:TableCell&gt;
          &lt;/asp:TableRow&gt;
          &lt;asp:TableRow&gt;
             &lt;asp:TableCell&gt;
                  &lt;h4&gt; Car model:&lt;/h4&gt;
             &lt;/asp:TableCell&gt;
             &lt;asp:TableCell&gt;
                  &lt;asp:TextBox ID="carmodel" runat="server" name="carmodel" Text='&lt;%#  Eval("car_model") %&gt;' Width="301px" CssClass="form-control"&gt;&lt;/asp:TextBox&gt;
             &lt;/asp:TableCell&gt;
          &lt;/asp:TableRow&gt;
          &lt;asp:TableRow&gt;
             &lt;asp:TableCell&gt;
                  &lt;h4&gt; Price: &lt;/h4&gt;
             &lt;/asp:TableCell&gt;
             &lt;asp:TableCell&gt;
                  &lt;asp:TextBox ID="price"  name="price" runat="server" Width="301px"  CssClass="form-control"&gt;&lt;/asp:TextBox&gt;
             &lt;/asp:TableCell&gt;
          &lt;/asp:TableRow&gt;
          &lt;asp:TableRow&gt;
             &lt;asp:TableCell&gt;
                  &lt;h4&gt; Discounted Price If: &lt;/h4&gt;
             &lt;/asp:TableCell&gt;
             &lt;asp:TableCell&gt;
                  &lt;asp:TextBox ID="d_price" name="d_price" runat="server" Width="301px"  CssClass="form-control"/&gt;
             &lt;/asp:TableCell&gt;&lt;/asp:TableRow&gt;&lt;asp:TableRow&gt;
             &lt;asp:TableCell&gt; &lt;h4&gt;Car image (Type url)&lt;/h4&gt;&lt;/asp:TableCell&gt;&lt;asp:TableCell&gt;
                  &lt;asp:TextBox CssClass="form-control" ID="image"  name="image" runat="server" /&gt;Just Location
              &lt;/asp:TableCell&gt;&lt;/asp:TableRow&gt;&lt;asp:TableRow&gt;
             &lt;asp:TableCell&gt;&lt;h4&gt;Avilability&lt;/h4&gt;&lt;/asp:TableCell&gt;&lt;asp:TableCell&gt;
                   &lt;asp:TextBox CssClass="form-control" ID="avail"  name="avail" runat="server" /&gt;Just Location
             &lt;/asp:TableCell&gt;&lt;/asp:TableRow&gt;&lt;asp:TableRow&gt;
             &lt;asp:TableCell&gt;&lt;h4&gt;Quantity&lt;/h4&gt;&lt;/asp:TableCell&gt;&lt;asp:TableCell&gt;
                   &lt;asp:TextBox CssClass="form-control" ID="quantity"   name="quantity" runat="server" /&gt;Just Location
             &lt;/asp:TableCell&gt;&lt;/asp:TableRow&gt;&lt;asp:TableRow&gt;
             &lt;asp:TableCell&gt;
                  &lt;h4&gt;Long description &lt;/h4&gt;
             &lt;/asp:TableCell&gt;&lt;asp:TableCell&gt;
  
                  &lt;asp:TextBox ID="details" name="details" runat="server" Width="295px"  CssClass="form-control" Height="81px" TextMode="MultiLine"&gt;&lt;/asp:TextBox&gt;
             &lt;/asp:TableCell&gt;&lt;/asp:TableRow&gt;&lt;asp:TableRow&gt;
             &lt;asp:TableCell&gt;
                  &lt;h4&gt;Year &lt;/h4&gt;
             &lt;/asp:TableCell&gt;&lt;asp:TableCell&gt;
                  &lt;asp:TextBox ID="year" name="year" runat="server" Width="295px"  CssClass="form-control" &gt;&lt;/asp:TextBox&gt;
             &lt;/asp:TableCell&gt;&lt;/asp:TableRow&gt;&lt;asp:TableRow&gt;
             &lt;asp:TableCell&gt;
                  &lt;h4&gt;Special Discounted(0 0r 1) &lt;/h4&gt;
             &lt;/asp:TableCell&gt;&lt;asp:TableCell&gt;
                  &lt;asp:TextBox ID="special" name="special"  runat="server" Width="295px"  CssClass="form-control"  &gt;&lt;/asp:TextBox&gt;
             &lt;/asp:TableCell&gt;&lt;/asp:TableRow&gt;&lt;/asp:Table&gt;&lt;asp:Button ID="button" OnClick="button_click" runat="server"  Cssclass="btn btn-primary btn-lg btn-block" Text="Update the car" /&gt;
  
     &lt;/form&gt;
  </code></pre>
  
  <p>
   </p>
  
  <p>HERE is the code fore cs</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.Web.Services;
  using System.Configuration;
  using System.Data;
  using MySql.Data.MySqlClient;
  
  public partial class Editcar : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
  
      using (MySqlConnection con = new MySqlConnection(constr))
      {
          var id = Request.QueryString["id"];
          string selectquery = "SELECT * FROM product WHERE id=" + @id;
          MySqlCommand cmd = new MySqlCommand(selectquery);
          cmd.Connection = con;
          cmd.CommandType = CommandType.Text;
          con.Open();
          cmd.ExecuteNonQuery();
  
          MySqlDataAdapter da = new MySqlDataAdapter(cmd);
          DataTable dt = new DataTable();
          da.Fill(dt);
  
          foreach (DataRow dr in dt.Rows)
  
          {
              newid.Text = dr["id"].ToString();
              carmake.Text = dr["car_make"].ToString();
              carmodel.Text = dr["car_model"].ToString();
              price.Text = dr["unitprice"].ToString();
              d_price.Text = dr["discountprice"].ToString();
              image.Text = dr["image"].ToString();
              quantity.Text = dr["quantity"].ToString();
              avail.Text = dr["availability"].ToString();
              details.Text = dr["details"].ToString();
              year.Text = dr["year"].ToString();
              special.Text = dr["special"].ToString();
          }
      }
  }
  
  public void button_click(object sender, EventArgs e)
  {
      string constor = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
      MySqlConnection conn = new MySqlConnection(constor);
  
      string sql = "Update product SET car_make=@carmake, car_model=@carmodel, UnitPrice=@price, Discountprice=@d_price, image=@image, Quantity=@quantity, availability=@avail, details=@details, year=@year, special=@special  WHERE id= @id";
      var cmd = new MySqlCommand(sql, conn);
  
      conn.Open();
      cmd.Parameters.AddWithValue("@id", newid.Text);
      cmd.Parameters.AddWithValue("@carmake", carmake.Text);
      cmd.Parameters.AddWithValue("@carmodel", carmodel.Text);
      cmd.Parameters.AddWithValue("@price", price.Text);
      cmd.Parameters.AddWithValue("@d_price", d_price.Text); // put zero if no discount
      cmd.Parameters.AddWithValue("@image", image.Text);
      cmd.Parameters.AddWithValue("@quantity", quantity.Text);
      cmd.Parameters.AddWithValue("@avail", avail.Text);
      cmd.Parameters.AddWithValue("@details", details.Text);
      cmd.Parameters.AddWithValue("@year", year.Text);
      cmd.Parameters.AddWithValue("@special", special.Text);
      cmd.Parameters.AddWithValue("@id", newid.Text);
  
      var ex = cmd.ExecuteNonQuery();
  
      if (ex == 1)
      {
          Response.Redirect("AdminList.aspx");
      }
      else
      {
          Response.Write("Error");
      }
      conn.Close();
  }
  }
  </code></pre>
  
  <p>It's Just updating but not getting the table value</p>
  
  <p>I used ajax too it didn't work</p>