Rebind DataGridView DataSource


  • I am doing a little thing where I dynamically create tables when there are changes made to the main database table. I bind to the context table. We can call it "Context". Then a user desides to make  new report. A new report table with a timestamp is produces. We can call it "Report_TimeStamp", "Report_TimeStamp2", "Report_TimeStamp3" and so on...

    Now that there are a few Reports tables. I would like to go in and one of them. So I do that by calling  a stored procedure that populates the Context table with the values from the chosen Report table.  I need a way to rebind the datasource(Context Table) to update the values so that they reflect the Reports data I am working on.



    this.contextDataGridView.DataSource = contextBindingSource;


    I thought the preceding line might do the trick but the next time I try to save the data I get a concurrency error.

    Concurrency violation: the UpdateCommand affected 0 of the expected 1 records.


    So as soon as the underlying data doesn't match up with what the datagridview expects there is a problem. Is there an easy way to rebind this data with the new datasource?


    Thanks, Jaime


    Thursday, November 01, 2007 8:07 AM


  • this.contextTableAdapter.Fill(this.reportsDataSet.Context);



    worked for me. I guess I forgot to get the data from the database. I am not even sure I need the call to the reset bindings. I just noticed it in someones post.



    Thursday, November 01, 2007 8:16 AM