none
how to delete a row in a datagrid in windows form application in c# RRS feed

  • Question

  • I have a windows form where i have loaded a employee details table to a datagrid i have a delete button

    when i select a row and press on delete button it should delete.I have created a stored procedure for delete and a class file where i have written delete function it is done using  employee id .I am confused what to write in delete button.

    • Moved by Mike FengModerator Monday, June 11, 2012 10:43 AM Data (From:.NET Base Class Library)
    Sunday, June 10, 2012 12:34 PM

Answers

  • Hi Gagan,

    You could achieve this by delete method of TableAdapter. You just need to change the command type of delete to Stored Procedure and select the command text as stored procedure name which lies in SQL Server side. You could call this stored procedure as TableAdapter.Delete() in your code.

    In the delete button, you could call the delete stored procedure like above or use the class’s instance or static method to do it (in case of you wrapped above statement into this class).

    Please refer to the following figure for quick understanding:

    Hope this could help you.

    Best Regards,


    Tony Xiao [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 12, 2012 11:41 AM
    Moderator

All replies

  • This forum about the system.object class and what is related to that seems to me not such a so well forum for your question.

    Are you sure that it is a DataGrid, because that works only in combination with DataSets and therefore strange in the way you describe.

    Otherwise try the forum for the DataGrid 

    http://social.msdn.microsoft.com/Forums/en-US/winforms/threads

    or as it is about a DataSet the forum for that one.

    http://social.msdn.microsoft.com/Forums/en-US/adodotnetdataset/threads


    Success
    Cor

    Monday, June 11, 2012 5:55 AM
  • http://www.dotnetcurry.com/ShowArticle.aspx?ID=132

    Mark Answered, if it solves your question and Vote if you found it helpful.
    Rohit Arora

    Monday, June 11, 2012 6:31 AM
  • Hi Gagan,

    You could achieve this by delete method of TableAdapter. You just need to change the command type of delete to Stored Procedure and select the command text as stored procedure name which lies in SQL Server side. You could call this stored procedure as TableAdapter.Delete() in your code.

    In the delete button, you could call the delete stored procedure like above or use the class’s instance or static method to do it (in case of you wrapped above statement into this class).

    Please refer to the following figure for quick understanding:

    Hope this could help you.

    Best Regards,


    Tony Xiao [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, June 12, 2012 11:41 AM
    Moderator