954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Unable to deleta a row using grid view

how can i write a code for deleting a row using gridview

#
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
#
{
#
GridViewRow row = GridView1.Rows[e.RowIndex];
#
 
#
objCust.CustId = Convert.ToInt32(objCust.findCustId().Tables[0].Rows[0][0].ToString());
#
 
#
objCust.DeleteNewUser();
#
 
#
if (objCust.DeleteNewUser() == 1)
#
{
#
bindGvEdit();
#
}
#
}


But I am getting a error as

CS0019: Operator '==' cannot be applied to operands of type 'System.Data.DataSet' and 'int'

Plz suggest how to rectify...

I have written stored procedure for DeleteNewUser in Sql server 2005... I am using visual studio 2005 as well..

geniusvishal
Junior Poster in Training
58 posts since Jan 2012
Reputation Points: 9
Solved Threads: 4
 

Do you guys need any more info regarding this??

geniusvishal
Junior Poster in Training
58 posts since Jan 2012
Reputation Points: 9
Solved Threads: 4
 

The error is in the 18th line.. But I am unable to figure it out my table name is tblCust.. and the bindEvEdit code is:

public void bindGvEdit()
    {
        GridView1.DataSource = objCust.SelectallNewUser();
        GridView1.DataBind();
    }
geniusvishal
Junior Poster in Training
58 posts since Jan 2012
Reputation Points: 9
Solved Threads: 4
 

Your 18 line is if (objCust.DeleteNewUser() == 1), which clearly indicates that DeleteNewUser() is returning the dataset and you are comparing it with 1 that is integer. Please check your function and SP.

sufyan2011
Junior Poster
166 posts since Dec 2011
Reputation Points: 9
Solved Threads: 20
 

@Sufyan 2011 Thx Yep i was wrong.. Actually I was comparing an integer with a dataset...
Actually Guys the problem was with the Bll; Which would look like:

public int DeleteNewUser()
        {
            DBAccess db = new DBAccess();
            db.AddParameter("@iCustId", iCustId);
            return db.ExecuteNonQuery("[tblCust_Delete]",true);
        }

and the modified code would be:

protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
       
        GridViewRow row = GridView1.Rows[e.RowIndex];

        objCust.CustId = Convert.ToInt32(GridView1.DataKeys[row.RowIndex].Value);

        if (objCust.DeleteNewUser() > 0)
        {
            bindGvEdit();
        }
    }
geniusvishal
Junior Poster in Training
58 posts since Jan 2012
Reputation Points: 9
Solved Threads: 4
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You