title: add, update and delete database data from code behind using asp.net C#
body: <p>my connection string is:</p>
  
  <pre><code>&lt;connectionStrings&gt;
  &lt;add name="NorthwindConnectionString" 
  connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SecurityTutorials.mdf;Integrated Security=True;User Instance=True" 
  providerName="System.Data.SqlClient"/&gt;
  &lt;/connectionStrings&gt;
  </code></pre>
  
  <p>and by using the below line i'll connect to the database from code behind:</p>
  
  <pre><code>connection = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString)
  </code></pre>
  
  <p>currently i'm using below code at my .aspx page to add, update and delete the data from database.</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
          ConnectionString="&lt;%$ ConnectionStrings:NorthwindConnectionString %&gt;" 
          SelectCommand="SELECT [ProductID], [ProductName], [Discontinued] FROM [Alphabetical list of products]"
          InsertCommand = "INSERT INTO [Alphabetical list of products] (ProductID, ProductName, Discontinued)VALUES(@ProductID,@ProductName,@Discontinued)"
          UpdateCommand = "UPDATE [Alphabetical list of products] SET [ProductName] = @ProductName WHERE [ProductID] = @ProductID"
          DeleteCommand = "DELETE FROM [Alphabetical list of products] WHERE [ProductID]=@ProductID"&gt;
          &lt;InsertParameters&gt;
              &lt;asp:Parameter Name="ProductID" Type="String" /&gt;
              &lt;asp:Parameter Name="ProductName" Type="String" /&gt;
              &lt;asp:Parameter Name="Discontinued" Type="String" /&gt;
          &lt;/InsertParameters&gt;           
          &lt;UpdateParameters&gt;
              &lt;asp:Parameter Name="ProductName" Type="String" /&gt;             
              &lt;asp:Parameter Name="ProductID" Type="Int32" /&gt;
          &lt;/UpdateParameters&gt;
          &lt;DeleteParameters&gt;
              &lt;asp:Parameter Name="ProductID" Type="Int32" /&gt;
          &lt;/DeleteParameters&gt;
      &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>i'm using ListView and by the below code i could access to all and edit all the data of the database from code behind:</p>
  
  <pre><code> using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString))
      {
          var selectCommand = new SqlCommand("SELECT [ProductID], [ProductName], [Discontinued] FROM [Alphabetical list of products]");
          var dataAdapter = new SqlDataAdapter();
          var dataSet = new DataSet();
          selectCommand.CommandType = CommandType.Text;
          selectCommand.Connection = connection;
          dataAdapter.SelectCommand = selectCommand;
  
          connection.Open();
          dataAdapter.Fill(dataSet, "myDataSet");
          connection.Close();
          foreach (DataRow dr in dataSet.Tables["myDataSet"].Rows)
          {
              dr["ProductID"] = dr["ProductID"]+"00";
          }   
  
          ListView1.DataSource = dataSet;
          ListView1.DataBind();
      }
  </code></pre>
  
  <p>my question is how can i do the add, edit, update and delete from the code behind and delete the  from the .aspx page. because i'm developing a template and i want to do every thing from code behind.<br />
  appreciate your consideration.</p>