Becky Bloomwood

Becky Bloomwood

  • NA
  • 119
  • 285.8k

Delete records from database through 3-tier programming

Feb 8 2011 4:27 AM

Hi, currently I am doing an online store web application. I am trying to do a delete record w/o the use of primary key.
In Ms sql server 2008 database, it contains all these fields: itemName, itemDesc, category, catID(FK).
itemName     itemDesc                                        category     catID(FK)
dress             Dress with flowers at the side      Floral          1
Skirt               Skirt with flower petals                 Floral          1
 
This is the database.cs:  
 

public bool Delete_ItemsRecords(string catID)
        {
            SqlCommand cmd_ItemsList = new SqlCommand();
            cmd_ItemsList.CommandText = "[VRM].[DELETE_ItemsRecords]";
            cmd_ItemsList.CommandType = CommandType.StoredProcedure;
            cmd_ItemsList.Parameters.Clear();
            SqlParameter sqlParaCatID = new SqlParameter("@catID", SqlDbType.VarChar, 10);
            sqlParaCatID.Value = catID;
            cmd_CriticalTermsList.Parameters.Add(sqlParaCatID);
            return executeNotQuery(cmd_ItemsList);
        }

This is the stored procedure:
 
 ALTER PROCEDURE [OS].[DELETE_ItemsRecords] 
@catID varchar(10)
AS
BEGIN
 DELETE FROM OS.Items WHERE catID = @catID
END

This is the business logic:
 

protected void gvItems_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
vrmdb.Delete_ItemsRecords(gvItems.DataKeys[e.RowIndex].Values[0].ToString());
BindGrid(
true);
}

When I try to delete the record I am unable to do it. I try it for those grid view that uses PK to delete works. May I know how to resolve it? Thanks!

Answers (4)