locked
BindingSource Doesn't Change Row States RRS feed

  • Question

  • Hello,
    I have a bit strange problem in my application. I have more binding sources then one in my different forms. All of them work great when editing, deleting the data except one. But this one is a bit different from others. I'm using it only for updating and deleting. You can't add new records using it. And also its dataset doesn't contains any Insert commands in it. That's the difference. Now problem is:

    After deleted the rows (using BindingSource.RemoveCurrent), it doesn't mark rows as deleted. I call BindingSource.Count method after deleted rows, it sill counts deleted rows. So it seems it doesn't update the dataset. But it is. Dataset.HasChanges returns true.  So there is no problem with it. The only problem is counting the rows as wrong. I think BS doesn't update itself after the deleting. What's your opinions?
    Tuesday, March 16, 2010 9:47 PM

Answers

  • Hi Justin.NET,

    When you use BindingSource.RemoveCurrent, it actually does not remove the row in the data table, it just mark the row as deleted. The row count in data table does not change. DataSet.HasChanges() will return true because the row state changed from Unchanged to Deleted.  BindingSource.RemoveCurrent has the same function with using DataRow.Delete. If you want to remove the row from data table (but not mark it as deleted)please use DataRowCollection's remove or RemoveAt method.

    Best regards,
    Alex Liang





    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Justin.NET Thursday, March 18, 2010 6:02 PM
    Thursday, March 18, 2010 4:06 AM
  • Hi Justin,

    The Remove methods remove a row from a list, in this case a datatable.
    Which means that there is nothing anymore which can be used to remove the row from the database.

    If you use Delete from the collection, then the rowstate is set to Deleted and it will if you have correct set the delete command in your Adapter (or generated or used the commandbuilder) then the row will be removed from the database and if you use a dataadapter, be removed by that in the dataset as last step.

    It was one of my first mistakes with Net as well.

    http://msdn.microsoft.com/en-us/library/33y2221y.aspx

    I never did this with a bindingsource but I assume it will be

    DataTable.Rows(TheBindingSource.Position).Delete

    Will you try it and response if it did what it has to do for you ?


    Success
    Cor
    • Marked as answer by Justin.NET Thursday, March 18, 2010 6:01 PM
    Thursday, March 18, 2010 7:45 AM

All replies

  • Hello,
    I have a bit strange problem in my application. I have more binding sources then one in my different forms. All of them work great when editing, deleting the data except one. But this one is a bit different from others. I'm using it only for updating and deleting. You can't add new records using it. And also its dataset doesn't contains any Insert commands in it. That's the difference. Now problem is:

    After deleted the rows (using BindingSource.RemoveCurrent), it doesn't mark rows as deleted. I call BindingSource.Count method after deleted rows, it sill counts deleted rows. So it seems it doesn't update the dataset. But it is. Dataset.HasChanges returns true.  So there is no problem with it. The only problem is counting the rows as wrong. I think BS doesn't update itself after the deleting. What's your opinions?
    http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.removecurrent(VS.80).aspx


    Just Be Humble Malange!
    Tuesday, March 16, 2010 10:54 PM
  • Hello,
    I have a bit strange problem in my application. I have more binding sources then one in my different forms. All of them work great when editing, deleting the data except one. But this one is a bit different from others. I'm using it only for updating and deleting. You can't add new records using it. And also its dataset doesn't contains any Insert commands in it. That's the difference. Now problem is:

    After deleted the rows (using BindingSource.RemoveCurrent), it doesn't mark rows as deleted. I call BindingSource.Count method after deleted rows, it sill counts deleted rows. So it seems it doesn't update the dataset. But it is. Dataset.HasChanges returns true.  So there is no problem with it. The only problem is counting the rows as wrong. I think BS doesn't update itself after the deleting. What's your opinions?
    http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.removecurrent(VS.80).aspx


    Just Be Humble Malange!

    Where should I look?  I already do this.
    Tuesday, March 16, 2010 11:19 PM
  • Hi Justin.NET,

    When you use BindingSource.RemoveCurrent, it actually does not remove the row in the data table, it just mark the row as deleted. The row count in data table does not change. DataSet.HasChanges() will return true because the row state changed from Unchanged to Deleted.  BindingSource.RemoveCurrent has the same function with using DataRow.Delete. If you want to remove the row from data table (but not mark it as deleted)please use DataRowCollection's remove or RemoveAt method.

    Best regards,
    Alex Liang





    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Justin.NET Thursday, March 18, 2010 6:02 PM
    Thursday, March 18, 2010 4:06 AM
  • Hi Justin,

    The Remove methods remove a row from a list, in this case a datatable.
    Which means that there is nothing anymore which can be used to remove the row from the database.

    If you use Delete from the collection, then the rowstate is set to Deleted and it will if you have correct set the delete command in your Adapter (or generated or used the commandbuilder) then the row will be removed from the database and if you use a dataadapter, be removed by that in the dataset as last step.

    It was one of my first mistakes with Net as well.

    http://msdn.microsoft.com/en-us/library/33y2221y.aspx

    I never did this with a bindingsource but I assume it will be

    DataTable.Rows(TheBindingSource.Position).Delete

    Will you try it and response if it did what it has to do for you ?


    Success
    Cor
    • Marked as answer by Justin.NET Thursday, March 18, 2010 6:01 PM
    Thursday, March 18, 2010 7:45 AM
  • Thanks now I understand. Actually I remembered I asked this before in a different thread :) 

    Thursday, March 18, 2010 5:59 PM