Delete selected record on Button click. I am using MS Access as a Database in C#.
How it can be done ??

Recommended Answers

All 3 Replies

string code;
            code = textBox.Text;
            r = dp.Tables[Tablename].Rows.Find(code);
            r.Delete();
            db.Update(dp);

r is datarow.
dp is dataset
db is dataAdapter.

You can find the row that u want to delete by entering a column name.
And then this code would delete that row and would also update your table.

#Aspx Page
#-----------
# This is the template filed of the grid view... Grid view template column for the check boxk
<asp:TemplateField HeaderText="Select">
                                            <ItemTemplate>
                                                <asp:CheckBox ID="chkSelect" runat="server" />
                                            </ItemTemplate>
                                        </asp:TemplateField>

# button
<asp:Button ID="btnDelete" runat="server" Text="Delete" Width="10%" OnClick="btnDelete_Click1" />


#Code
#------------
 
protected void btnDelete_Click1(object sender, EventArgs e)
    {
        
        foreach(GridViewRow row in GridView1.Rows)
        {

            CheckBox cb = (CheckBox)row.FindControl("chkSelect");

            if (cb.Checked && cb != null)
            {

                int ID_No= Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);
                		
		# Make query for Deleting Row form Category ID  example : delete * from table where id=ID_No               
		
               
            }
        }
		
	# Rebind Grid View Here.
       

    }

Regards,
jay

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.