Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8206707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:45:51+00:00 2026-06-07T08:45:51+00:00

This is my code I want to delete the row when that row’s DELETE

  • 0

This is my code I want to delete the row when that row’s DELETE button is clicked and at the same time the database should also get updated.

    protected void gvDetails_RowCommand(object sender, GridViewCommandEventArgs e)
    {
     if (e.CommandName.Equals("Delete"))
     {
        int index = Convert.ToInt32(e.CommandArgument);
        GridViewRow row = gvDetails.Rows[index];
        string productID = gvDetails.DataKeys[index].Value.ToString();
        string productName = row.Cells[1].Text;
        this.RemoveProduct(productID, productName);
     }
    }
public void RemoveProduct(string productID, string productName)
{
   DataRow dr;
   SQLConnection objcon;
   SqlDataAdapter objadp;
   objcon=new SqlConnection("Connecting string");
    try
    {
        objcon.Open();
        DataSet ds = new DataSet();
        objadp = new SqlDataAdapter("Select *from Bus_Table", objcon);
        objadp.Fill(ds, "Bus_Table");
        objadp.DeleteCommand = objcon.CreateCommand();
        objadp.DeleteCommand.CommandText = "DELETE from Bus_Table where B_ID=" +int.Parse(productID);
        DataTable objtable = new DataTable();
        ds.Tables.Add(objtable);
        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            if (dr["B_ID"].Equals(productID))
            {
                DataRow objrow = dr;
                objrow.Delete();
                objadp.Update(ds, "Bus_Table");
                ds.AcceptChanges();
                Response.Write("Bus Deleted");
                break;
            }
        }
    }
    catch (SqlException ex)
    {
        Response.Write(ex.Message);
    }
    finally
    {
        objcon.Close();
    }
}

When I am compiling this code am getting an error:

“Deleting is not supported by data source ‘SqlDataSource1′(my data source) unless DeleteCommand is specified”.

When I put a breakpoint I noticed that the RemoveProduct(string productID, string productName) is not getting called from gvDetails_RowCommand() but the entry gets deleted too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T08:45:54+00:00Added an answer on June 7, 2026 at 8:45 am

    take a look at these articles, it would explain in detail on how to delete single/multiple rows from gridview.
    http://technico.qnownow.com/2012/06/15/how-to-delete-multiple-rows-from-gridview-with-checkboxes/
    http://technico.qnownow.com/2012/06/14/how-to-delete-a-row-from-gridview-with-client-side-confirmation/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to delete a file into recycle bin. I using this code. SHFILEOPSTRUCT
I have this code and I want to have my button as a square,
I have this code that I want to make point-free; (\k t -> chr
This code isn't localized: Enum.GetNames(typeof(DayOfWeek)) I want a method that returns a list of
I want to delete a database row which contains a file name when the
I have a button used to delete a row when checked that calls the
I want to delete a row from the database. I added the row to
i have a form with 6 textboxes and a delete button.that i want to
according to this code if i want to access imageView1 and imageView2 how can
I have C code and I want to compile and run this code in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.