title: I can't get rowdeleting in gridview to delete database entry
body: <p>I'm currently in the process of creating an asp.net web app in C# using Visual Studio. I have been stuck on the same problem for a while now and have tried so many solutions. I am required to have a page that upon loading, displays some of the information stored in a database table (first name, dob &amp; username (PK) for children that have registered on a previous page.</p>
  
  <p>I have no problem populating the grid view with this data, but I am required to have delete button/links next to each child, that delete the child completely from the database table. This is what I can not get to work. My code was a complete mess, full of commented out sections where I was trying new things. As of right now, I have scaled it back to a simple section of code, and I am getting an error when clicking delete next to any of the children in gridview. </p>
  
  <p>Is it really this difficult to enable the delete function in gridview? I have supplied screenshots, along with my code. If anyone can point out where i'm going wrong, I would be ever so grateful! Thanks in advance.</p>
  
  <p><a href="https://i.stack.imgur.com/ECYG5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ECYG5.png" alt="Screenshot of error I get when hitting delete"></a></p>
  
  <p>.CS CODE:</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.Data.SqlClient;
  using System.Data;
  using System.Diagnostics;
  using System.Collections;
  using System.Configuration;
  
  namespace Coursework
  {
  public partial class viewandremove : System.Web.UI.Page
  {
      protected void Page_Load(object sender, EventArgs e)
      {
          using (SqlConnection connect = new SqlConnection("Data Source=THEBEAST;Initial Catalog=newregDB;Integrated Security=True;Pooling=False"))
          using (SqlCommand cmd = new SqlCommand("SELECT [firstname], [dob], [ChildID] FROM [children]", connect))
          {
              connect.Open();
              SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(cmd);
              DataTable dt = new DataTable();
              sda.Fill(dt);
              GridView1.DataSource = dt;
              GridView1.DataBind();
              connect.Close();
          }
      }
  
      protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
      {
  
      }      
      protected void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
      {
  
      }
  
      protected void Gridview1_RowDeleting(object sender, GridViewDeleteEventArgs e)
      {          
          using (SqlConnection connect = new SqlConnection("Data Source=THEBEAST;Initial Catalog=newregDB;Integrated Security=True;Pooling=False"))
          using (SqlCommand cmd = new SqlCommand("DELETE FROM children where childID=", connect))
          {
              connect.Open();
              SqlDataAdapter sda = new System.Data.SqlClient.SqlDataAdapter(cmd);
              DataTable dt = new DataTable();
              sda.Fill(dt);
              GridView1.DataSource = dt;
              GridView1.DataBind();
              connect.Close();
          }
      }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>SOURCE CODE:</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="viewandremove.aspx.cs" Inherits="Coursework.viewandremove" %&gt;
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"&gt;
  &lt;p&gt;
      &lt;br /&gt;
      &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateDeleteButton="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowDeleting="Gridview1_RowDeleting" DataKeyNames="childID" OnSelectedIndexChanging="GridView1_SelectedIndexChanging"&gt;
      &lt;/asp:GridView&gt;
  &lt;/p&gt;
  &lt;p&gt;
  &lt;/p&gt;
  &lt;p&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p></p>